【发布时间】:2011-11-24 17:16:20
【问题描述】:
我正在尝试使用名为 EditColorDialog 的对话框更改 MainWindow 的背景颜色。该对话框可以很好地读取主窗口的当前背景颜色,但我似乎无法让它更改该颜色。
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();
}
}
我在主窗口代码中使用这个属性
public Brush background
{
get { return main_window.Background; }
set { main_window.Background = value; }
}
【问题讨论】:
-
在哪个部分?我正在使用一个名为“背景”的属性。
-
属性“应该”在 PascalCase 中。