1

In trying to set the color of a text box in my WPF application I did

enter image description here

Why do I get that error ?

And how to rectify it ?

0

2 Answers 2

5

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 };
    ...
Sign up to request clarification or add additional context in comments.

2 Comments

Alternatively, a Brush can be created from the given color: Brush brush = new SolidColorBrush(color)
Solved.Thanks.and @elgonzo , you are completely right too(I used your solution )
-1
textBox1.Background = Brushes.Blue;
textBox1.Foreground = Brushes.Yellow;

You can do like this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.