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?
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.
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"/>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With