20

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'

  • May help [Set system color to button](https://stackoverflow.com/a/28722540/2122718]) or [Set background color of Textbox](https://stackoverflow.com/a/979906/2122718) – marbel82 Jun 06 '17 at 07:29

1 Answers1

39
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.

Casey Price
  • 768
  • 7
  • 16
  • Yes that works , the message I guess was obvious sort of, but you did it! thx! –  Dec 09 '15 at 00:35