title: Changing MainWindow background color WPF
body: <p>I am trying to change the background color of the MainWindow using a dialogbox called EditColorDialog. The dialogbox can read the current background color of the main window just fine but I can't seem to get it to change that color.</p>
  
  <pre><code>public partial class EditColorDialog : Window
  {
      ColorDialog colorPicker = new ColorDialog();  //this is a colorpicker
      MainWindow mw = new MainWindow();
  
      public ColorDialog()
      {
          InitializeComponent();
          rect.Fill = mw.background;  //reads the color off the main window
      }
  
      private void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
      {
          colorPicker.Owner = this;
          if ((bool)colorPicker.ShowDialog())
          {
              //selects new color from colorpicker
              rect.Fill = new SolidColorBrush(colorPicker.SelectedColor);
          }
      }
  
      private void OkButton_Click(object sender, RoutedEventArgs e)
      {
          mw.background = rect.Fill;
          this.Close(); 
      }
  }
  </code></pre>
  
  <p>I am using this property in the main window code</p>
  
  <pre><code>public Brush background
  {
      get { return main_window.Background; }
      set { main_window.Background = value; }   
  }
  </code></pre>