How to set custom color picker color from a string?

1k Views Asked by At

I'm using the custom ColorPicker control provided by the Extended WPF Toolkit.

I have a configuration file where the application take the color, this color is in string format, like: #FFF0E68C.

Now I'm trying to convert the string in color and valorize the ColorPicker color in this way:

var converter = new BrushConverter();
var brush = (Brush)converter.ConvertFromString("#FFF0E68C");
MyColorPicker.SelectedColor = brush;

but on the last line I get this error:

Implicit conversion from the type 'System.Windows.Media.Brush' in 'System.Windows.Media.Color?'

I doesn't have any Media.Color in brush, how can I fix this? Maybe someone know a better solution for achieve this target?

Thanks in advance.

2

There are 2 best solutions below

0
On

May be you donn't need to use BrushConverter and Brush, you should use ColorConverter and Color

0
On

As @Mixim suggested, I simply solve the problem in this way:

var color = (Color)ColorConverter.ConvertFromString(settings.SyncCalendarColor);
MyColorPicker.SelectedColor = color;

Thanks :)