7

I am working on an application having both WinForms and WPF controls; In case of WinForms TextBox selected text Background color comes Blue and White respectively whereas in WPF TextBox it is LightBlue and Black.

As answered in these questions I can use SelectionBrush property(WPF 4) to change the selected text's background, but How can I change the foreground color of selected text?

How can you change the highlighted text color for a WPF TextBox?

How can I change the highlighted text color for a TextBox?

akjoshi
  • 15,374
  • 13
  • 103
  • 121

2 Answers2

9

You cannot, the control does not allow for it.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • 9
    This is true. Normally you can try to change the SystemColors by assigning them a new value in an object's Resources dictionary. But both the regular foreground and the selected text foreground are looking at the same key (ControlTextBrushKey) for the color. So you can't separate these two colors. – Trevor Elliott Jun 01 '12 at 15:26
  • 3
    @Moozhe +1 it seems your comment should be an answer! It's so useful – amiry jd Jun 17 '12 at 16:13
2

Starting with .net 4.8 it is possible in TextBox using TextBoxBase.SelectionTextBrush https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.textboxbase.selectiontextbrush?view=net-5.0

Woodman
  • 1,108
  • 9
  • 11