Irakli Lekishvili Irakli Lekishvili - 1 year ago 175
C# Question

How to convert color code into media.brush?

I have a rectangle that i want to fill with a color. When i write

Fill = "#FFFFFF90"
it shows me an error:

Cannot implicitly convert type 'string' to 'System.Windows.Media.Brush

Please give me some advice.

Answer Source

You could use the same mechanism the XAML reading system uses: Type converters

var converter = new System.Windows.Media.BrushConverter();
var brush = (Brush)converter.ConvertFromString("#FFFFFF90");
Fill = brush;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download