How I can cast color name to SolidColorBrush
type? I mean the word i.e. "Yellow".
SolidColorBrush scb = ??? ; // "Yellow"
Thank you!
How I can cast color name to SolidColorBrush
type? I mean the word i.e. "Yellow".
SolidColorBrush scb = ??? ; // "Yellow"
Thank you!
For getting the color, use:
Color col=(Color)ColorConverter.ConvertFromString("Red");
Then create your brush:
Brush brush=new SolidColorBrush(col);
or if you can use the Colors-enum
Brush brush=new SolidColorBrush(Colors.Red);
You cannot cast one to another. They are simply different concepts. A brush is brush and color is, well, a color. Just because a brush "paints" in a specific color, doesn't mean you can interchange one with another.
You can however create a SolidColorBrush with a specific color, for example:
var brush = new SolidColorBrush(Color.Yellow);
// Yellow is green + red
SolidColorBrush yellowBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 0));