How can I change the background and foreground colors of a WPF Textbox programatically in c#?
+14
A:
textBox1.Background = Brushes.Blue;
textBox1.Foreground = Brushes.Yellow;
Timbo
2009-06-11 08:06:01
Nice... hadn't seen the Brushes class before
James Hay
2009-06-11 08:07:23
If we want to set a hex value to the color attribute , how it can be done??
Sauron
2010-03-04 11:40:59
You could use something likeBrush brush = new SolidColorBrush( Color.FromRgb( r, g, b ) );
Timbo
2010-03-04 13:17:33
There is also the much prettier `LinearGradientBrush` :)
BlueRaja - Danny Pflughoeft
2010-04-29 21:45:43
+2
A:
I take it you are creating the TextBox in xaml? In that case you need to give the text box a name. Then in the code behind you can then set the Background property using a variety of brushes. The simplest of which is the SolidColorBrush:
myTextBox.Background = new SolidColorBrush(Colors.White);
James Hay
2009-06-11 08:06:13