Posts Tagged 'Brush'

Silverlight: Convert Hex RGB to Color

Spent a few minutes looking up the answer to this one:

I have an RGB color in traditional HTML Hex notation, like #1d5d8f. How do I create a SolidColorBrush in this color?

I’m sure I must be missing something easier, but here’s the C# code to do it:

byte r = System.Convert.ToByte("1d", 16);
byte g = System.Convert.ToByte("5d", 16);
byte b = System.Convert.ToByte("8f", 16);
Color s = Color.FromRgb(r, g, b);
Brush b = new SolidColorBrush(s);


TwitterCounter for @anthonyrstevens
Add to Technorati Favorites

RSS Feed

View Anthony Stevens's profile on LinkedIn