如何更改WPF TextBox的突出显示文本的前景色?

时间:2012-06-01 12:51:21

标签: c# .net wpf textbox background-foreground

我正在开发一个同时具有WinForms和WPF控件的应用程序;如果WinForms TextBox选择文本背景颜色分别为蓝色和白色,而在WPF TextBox中则为LightBlue和Black。

正如在这些问题中所回答的,我可以使用SelectionBrush属性(WPF 4)来更改所选文本的背景,但是如何更改所选文本的前景色?

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

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

2 个答案:

答案 0 :(得分:7)

你不能,控制不允许它。

答案 1 :(得分:2)

从 .net 4.8 开始,可以在 TextBox 中使用 TextBoxBase.SelectionTextBrush https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.primitives.textboxbase.selectiontextbrush?view=net-5.0