convert from Color to brush convert from Color to brush wpf wpf

convert from Color to brush


This is for Color to Brush....

you can't convert it, you have to make a new brush....

SolidColorBrush brush = new SolidColorBrush( myColor );

now, if you need it in XAML, you COULD make a custom value converter and use that in a binding


Brush brush = new SolidColorBrush(color);

The other way around:

if (brush is SolidColorBrush colorBrush)    Color color = colorBrush.Color;

Or something like that.

Point being not all brushes are colors but you could turn all colors into a (SolidColor)Brush.


SolidColorBrush brush = new SolidColorBrush( Color.FromArgb(255,255,139,0) )