Tor*_*tad 38
CaretElement是一个内部密封类,例如,无法通过数据模板进行自定义.至少,插入刷可以改变.
<TextBox Text="This is some random text" CaretBrush="Blue" />
Run Code Online (Sandbox Code Playgroud)
如果要在插入笔刷上使用线性渐变,可以这样做.
<TextBox Text="This is some random text" FontSize="20">
<TextBox.CaretBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Blue" Offset="0" />
<GradientStop Color="Red" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</TextBox.CaretBrush>
Run Code Online (Sandbox Code Playgroud)
我也尝试使用Visual Brush,但是插入符总是显示为一条小的垂直线.
因为框架使用背景颜色的反转来设置插入符号的颜色,如果将Background属性设置为{x:Null},那么最终将使用默认的黑色插入符号,在黑色背景上可以特别很难看到!
http://www.codeproject.com/Articles/34736/Changing-the-Caret-Colour-in-WPF
这个问题的简单解决方案是实际为Background属性指定一个值.如果您有黑色背景并想要一个白色插入符,您可以将Background属性的值设置为#00000000,这是完全透明的黑色(如果这有意义!).框架似乎忽略了颜色的不透明度组件,因此您最终得到透明背景和白色插入符号!
还有一个链接:http: //blogs.msdn.com/b/llobo/archive/2007/02/08/changing-caret-color-in-textbox.aspx