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);

I wrote a simple color converter function to solve this problem. The happy faces are really the number 8 and a parentheses, like this: 8).


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)); 

来自MSDN

SolidColorBrush mySolidColorBrush = new SolidColorBrush();

// Describes the brush's color using RGB values. 
// Each value has a range of 0-255.
mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);
myRgbRectangle.Fill = mySolidColorBrush;   
链接地址: http://www.djcxy.com/p/87984.html

上一篇: HTML中属性和属性有什么区别?

下一篇: Silverlight / WPF以十六进制颜色设置椭圆