Irakli Lekishvili Irakli Lekishvili - 1 month ago 12x
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.


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;