1

I am converting my application from WinFrom to WPF. I want equivalent to WPF of following line of code :

txtbox.SelectionColor = Color.Green;
daniyalahmad
  • 3,513
  • 8
  • 29
  • 52

2 Answers2

2

You need to use SelectionBrush for WPF -

textBox.SelectionBrush = new SolidColorBrush(Colors.Green);

Or simply -

textBox.SelectionBrush = Brushes.Green;

Changing textBox highlighted text color is not possible in WPF. Check this out for more details.

However you can achieve that for RixhTextBox though. Details can be found here - Change selected text color in RichTextBox.

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
1

just do something like this in your xaml code

 <TextBox SelectionBrush="Green"/> 

or in your code behind

   txtBox.SelectionBrush = new SolidColorBrush(Colors.Green);
BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47