Reputation: 23
For example,Consider:
Rectangle rect = new Rectangle();
rect.Fill = Brushes.Cyan;
Can I get the color value from a rect like this? I tried to extract color values, but it did not work.
Upvotes: 2
Views: 1868
Reputation: 9461
Yes, you can, but you need to cast Fill to correct Brush class, since Brush does not have color property (you need to cast it to SolidColorBrush):
Rectangle rect = new Rectangle();
rect.Fill = Brushes.Cyan;
System.Diagnostics.Debug.WriteLine(((SolidColorBrush)rect.Fill).Color);
There are different brushes in WPF, for some of them Color does not make sense.
Upvotes: 1