Set background color of WPF Textbox in C# code Anonymous User1817217-Jul-2013 Hi mindstick!How can I change the background and foreground colors of a WPF Textbox programmatically in c#?Thanks in advancewcfwcf Updated on 17-Jul-2013
shreesh chandra shukla
17-Jul-2013If 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");