Menu

WPF Hex to Brush Conversion

May 30, 2008 - .NET / C#
WPF Hex to Brush Conversion

I recently found myself needing to do this and it took longer than expected! Anyway here is my solution!

[source:c-sharp] BrushConverter bc = new BrushConverter();
Brush brush;
brush = (Brush)bc.ConvertFrom(ci.Colour);
txtSetterColor.Background = brush;
[/source]
Share

4 thoughts on “WPF Hex to Brush Conversion

avatar
Trevor

txtSetterColor.Background = (Brush)new BrushConverter().ConvertFrom(ci.Colour);

Reply
avatar
Jammer

Indeedy! Nice …

Reply
avatar
Goblin

Brush myBrush;
myBrush = new SolidColorBrush ( Color.FromArgb ( 255, 255, 0, 0 ) );

This one works too.

Or the fastest way:

myTextBox.Foreground = new SolidColorBrush ( Color.FromArgb ( 255, 255, 0, 0 ) );
myTextBox.Background = new SolidColorBrush ( Color.FromArgb ( 255, 0, 255, 0 ) );

Happy Coding

Reply
avatar
Kobe Bryant shoes

Took me time to read all the comments, but I really enjoyed the article. It proved to be very useful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! I’m sure you had joy writing this article.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*