Houman
Houman

Reputation: 66380

Wpf/Silverlight: How to convert hex value into Color?

I know how to create a SolidColorBrush of color blue and return it like this within a converter:

return new SolidColorBrush(Colors.Blue);

However what if I needed the SolidColorBrush to be of this Hex value? #44FFFF00 ?

How do I do that?

Thanks,

Upvotes: 15

Views: 11942

Answers (3)

Danish Khan
Danish Khan

Reputation: 1891

Try

(Brush)(new BrushConverter().ConvertFrom("#44FFFF00"));

much better IMHO

Upvotes: 8

Manius
Manius

Reputation: 3644

Try

new SolidColorBrush(Color.FromArgb(0x44FFFF00));

Upvotes: 2

Phil
Phil

Reputation: 6679

new SolidColorBrush(Color.FromArgb(0x44, 0xFF, 0xFF, 0));

(Documentation)

Note: Don't use Color.FromRgb() (without the A) if your code will be shared in both Silverlight and WPF, as the FromRgb method doesn't exist in Silverlight.

Upvotes: 19

Related Questions