Tuesday, October 12, 2010

How to Change Background Color on WPF C# Object

I search "how to change label background color on wpf c#" on google and i didn't found what i want. But I've found it just now, and i want to share it with you.

Suppose you had a label object named Label1 and you'd like to change its background color to hex color (something like #00000;)

So here's the code:

BrushConverter bc = new BrushConverter();
Brush brush = (Brush)bc.ConvertFrom("#00000");

// Change the background. I guess it'd work well on other object type like canvas or textbox
Label1.Background = brush;

Good luck!

No comments: