Convert system.windows.media.brush to hexadecimal color code

In my Windows Phone7 application, I placed the canvas and set its background color to some kind of hex color code. Now I can not get the color value of the hex code through C # code. I used the code below, but it gave the color value in system.windows.media.brush.Plz help me with the answer?

clr = Convert.ToString(clr1.Background);
+5
source share
1 answer

It seems to be returning Brush, and since you set the color, it should return SolidColorBrush. try it

var color = ((SolidColorBrush)clr1.Background).Color.ToString();

Example:

var color = new Color() {R = 0xF0, G = 0x10, B = 0x80};
var brush = new SolidColorBrush(color);
var hexcolor = brush.Color.ToString();

hexcolor equally "#00F01080"

+10
source

All Articles