简体   繁体   English

DataGridRow背景属性的默认值

[英]Default value of DataGridRow Background property

I was messing arround with DataGridRow 's Background and I found something weird. 我把DataGridRowBackground弄得一团糟,发现有些奇怪。
The background color of a DataGridRow appear white, and if you print it, you get the following output: DataGridRow的背景颜色显示为白色,如果进行打印,则会得到以下输出:

System.Console.WriteLine(row.Background.ToString());
-----OUTPUT-----
#FFFFFFFF

If you print Brushes.White , you get the same thing: 如果打印Brushes.White ,则会得到相同的结果:

System.Console.WriteLine(Brushes.White);
-----OUTPUT-----
#FFFFFFFF

Now, when compairing them: 现在,当对它们进行配对时:

System.Console.WriteLine(Brushes.White.Equals(row.Background));
-----OUTPUT-----
False

It says that they are different, which is weird, since they both are SolidColorBrush with the #FFFFFFFF value. 它说它们是不同的,这很奇怪,因为它们都是带有#FFFFFFFF值的SolidColorBrush

Is there a specific reason for DataGridRow not to use Brushes.White ? 是否有特定的原因让DataGridRow不使用Brushes.White
Is it a predefined SolidBrushColor ? 它是预定义的SolidBrushColor吗?

It's because you are comparing brushes, not colors. 这是因为您在比较画笔,而不是颜色。 SolidColorBrush nor Brush override Equals method therefore your're comparing it by reference and one brush not always equals another brush with the same color. SolidColorBrushBrush重写Equals方法都是通过引用对其进行比较,并且一个画笔并不总是等于另一个具有相同颜色的画笔。 Controls will use SystemColors , as defined in Windows, for default values. 控件将使用Windows中定义的SystemColors作为默认值。 To compare it you need to know they are both SolidColorBrush and then compare SolidColorBrush.Color 要进行比较,您需要知道它们都是SolidColorBrush ,然后比较SolidColorBrush.Color

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM