Reputation: 61382
Styling is a big feature of WPF. Surely it's possible to make a text box look exactly like the OS textbox?
I'm tired of the bleak desaturated color that the selection must have in order for the black text to be visible:
Is this fixable?
Upvotes: 10
Views: 3117
Reputation: 84647
In .NET 4.8 you can now set the AppContext flag UseAdornerForTextboxSelectionRendering
to false
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Controls.Text.UseAdornerForTextboxSelectionRendering=false"/>
</runtime>
</configuration>
And then use the new property SelectionTextBrush
to achieve this like
<TextBox Text="Test WPF TextBox"
SelectionBrush="#1174E6"
SelectionTextBrush="White"/>
Upvotes: 3
Reputation: 184346
Unfortunately it might be impossible, the selection highlighting is done via an overlaying rectangle (brilliant idea, isn't it?), this makes it hard to even get the selection background-color you want while retaining text readablility. (Try setting SelectionOpacity
to 1
)
Also the selected text portion does not appear to be styled so changing the foreground colour of the selection is not easily possible either.
Upvotes: 7
Reputation: 35584
Perhaps you need the SelectionBrush
? It's a dependency property. (Not sure if it's available in .NET version < 4).
For finding what the current system colors are, you can use SystemColors
class.
See an example here: WPF SystemColors: color of TextBox border.
Upvotes: 1