Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight/WPF sets ellipse with hexadecimal colour

I am trying to set a colour of an ellipse object in code behind. So far I'm doing it by using the SolidColorBrush method. Is there a way to insert the colour value in hexadecimal, like in CSS?

Here is a code that I am using:

ellipse.Fill = new SolidColorBrush(Colors.Yellow);
like image 282
Drahcir Avatar asked Dec 17 '22 08:12

Drahcir


1 Answers

Something like this would work

ellipse.Fill = 
    new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00DD")); 

(Edit: It looks like this is WPF only. Alex Golesh has a blog post here about his Silverlight ColorConverter)

Although I prefer the Color.FromRgb method

byte r = 255;
byte g = 0;
byte b = 221;
ellipse.Fill = new SolidColorBrush(Color.FromRgb(r,g,b)); 
like image 137
Ray Avatar answered Jan 01 '23 10:01

Ray