Home > DeveloperSection > Forums > Set background color of WPF Textbox in C# code
Ankit Singh

Total Post:341

Points:2389
Posted on    July-17-2013 3:23 AM

 WCF WCF 
Ratings:


 1 Reply(s)
 11203  View(s)
Rate this:
Hi mindstick!

How can I change the background and foreground colors of a WPF Textbox programmatically in c#?

Thanks in advance



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-17-2013 8:19 AM

Solution!

If you want to set the background using a Hex Color you could do this:

var bc = new BrushConverter();

myTextBox.Background = (Brush)bc.ConvertFrom("#FFXXXXXX");

OR

you could set up a SolidColorBrush resource in xaml, and then use findResource in codebehind

<SolidColorBrush x:Key="BrushFFXXXXXX">#FF8D8A8A</SolidColorBrush>

myTextBox.Background = (Brush)Application.Current.MainWindow.FindResource("BrushFFXXXXXX");


Don't want to miss updates? Please click the below button!

Follow MindStick