21

I have a WPF application in which I have to make several updates.

One of the updates is that I'm changing from a Label to a TextBox

I see in many examples of Textbox border color getting set from XAML , that is NOT going to work for me as there are Business rule conditions to have a Red or Black

I have tried:

lblValidMsg.BorderBrush = Brushes.Red;
lblValidMsg.BorderBrush = System.Drawing.Color.Red;     // converter.ConvertFromString("#FF0000"); //borderColor;


lblValidMsg.BorderBrush = SystemColors.Control;

private Color borderColor = Color.Gray;

I'm sure that it is "simple" but the constant different errors are like

Cannot implicitly convert type 'System.Drawing.Color' to 'System.Windows.Media.Brush'   

YES I am aware that I left the textbox name as the label name hence the starting with "lbl"

Update:

I see that people set the background and foreground, but that is not way i need to do

textBox1.Background = Brushes.Blue;
textBox1.Foreground = Brushes.Yellow;

I did try

lblValidMsg.BorderBrush = Brushes.Red;

That gives Cannot implicitly convert type 'System.Drawing.Color' to 'System.Windows.Media.Brush'

1

1 Answer 1

40
textBox.BorderBrush = System.Windows.Media.Brushes.Red;

Works for me, make sure you're not using the System.Drawing.Brushes, you need to use the Windows.Media brush instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes that works , the message I guess was obvious sort of, but you did it! thx!

Your Answer

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