Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fill a Rectangle with a Hexadecimal color value?

Tags:

c#

.net

colors

wpf

'#10eeee'

Here's what I'm trying to do:

groupRectangle.Fill = Color.FromHex?
like image 989
Sergio Tapia Avatar asked Dec 28 '22 11:12

Sergio Tapia


1 Answers

You're looking for ColorConverter.ConvertFromString.

Color color = (Color)ColorConverter.ConvertFromString("#10eeee");
SolidColorBrush myBrush = new SolidColorBrush(color);

You will need using System.Windows.Media; at the top of your program too.

The following string Color formats should be supported.

Edit: You can also use BrushConverter.

like image 164
Brian R. Bondy Avatar answered Jan 17 '23 15:01

Brian R. Bondy