The WPF TextBox natively makes use of the System Highlight color for painting the background of selected text. I would like to override this and make it consis
This is a Windows 8.1 .Net 4.6.1 tested solution to customize the SelectionBrush of each TextBox in the app:
/// Constructor in App.xaml.cs
public App() : base()
{
// Register an additional SelectionChanged handler for appwide each TextBox
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.SelectionChangedEvent, RoutedEventHandler(_textBox_selectionChanged));
}
private void _textBox_selectionChanged(object sender, RoutedEventArgs e)
{
// Customize background color of selected text
(sender as TextBox).SelectionBrush = Brushes.MediumOrchid;
// Customize opacity of background color
(sender as TextBox).SelectionOpacity = 0.5;
}
If you want to include RichTextBox replace type name TextBox 4 times by TextBoxBase.