Reputation: 2256
In trying to set the color of a text box in my WPF application I did
Why do I get that error ?
And how to rectify it ?
Upvotes: 1
Views: 584
Reputation: 66439
It's telling you right in the error. The Background
property is of type System.Windows.Media.Brush
, not System.Windows.Media.Color
, so you can't assign a Color
to it.
Pass a Brush
into your method instead of a Color
, and assign that to the Background
property.
public void addToStackPanel(string argBuiltAlarm, Brush brush)
{
...
TextBox textBox = new TextBox { Background = brush };
...
Upvotes: 5
Reputation: 2210
textBox1.Background = Brushes.Blue;
textBox1.Foreground = Brushes.Yellow;
You can do like this.
Upvotes: -1