tags:

views:

527

answers:

1

Hi All,

Does anyone know how to convert a string that represents a color into a SolidColorBrush in wpf?

For e.g:

string colorRed = "Red"; SolidColorBrush fromStringToColor = new SolidColorBrush(colorRed);

That's sort of what I'm trying to accomplish. Any ideas?

Thanks in advance.

+8  A: 

You have to convert the string to a System.Windows.Media.Color, which you can do using the static ColorConverter.ConvertFromString method:

string colorRed = "Red";
Color c = (Color)ColorConverter.ConvertFromString(colorRed);
SolidColorBrush fromStringToColor = new SolidColorBrush(c);
Guy Starbuck