15

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,

1

3 Answers 3

19
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.

Sign up to request clarification or add additional context in comments.

Comments

8

Try

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

much better IMHO

1 Comment

For those of you that (like me) didn't have the namespaces already, here it is fully spelled out. (System.Windows.Media.Brush)(new System.Windows.Media.BrushConverter().ConvertFrom("#44FFFF00"));
2

Try

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

1 Comment

This doesn't work in Silverlight: No overload for method 'FromArgb' takes 1 arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.