Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert color code into media.brush? [duplicate]

Tags:

c#

wpf

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.

like image 459
Irakli Lekishvili Avatar asked Jul 24 '11 18:07

Irakli Lekishvili


People also ask

What is Brush in wpf?

The following list describes the different types of WPF brushes: SolidColorBrush: Paints an area with a solid Color. LinearGradientBrush: Paints an area with a linear gradient. RadialGradientBrush: Paints an area with a radial gradient. ImageBrush: Paints an area with an image (represented by an ImageSource object).


1 Answers

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; 
like image 65
H.B. Avatar answered Sep 22 '22 14:09

H.B.