文本框插入符号样式 [英] TextBox Caret Styling

查看:32
本文介绍了文本框插入符号样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些关于在 WPF4 中设置 CaretBrushes 的内容,但有没有人真正改变过插入符号本身?

I've found a few things on setting CaretBrushes in WPF4, but has anybody actually ever changed the caret itself?

我想做的是在 INSERT 模式下使用 OVERWRITE 插入符号.我见过来自 .Net 3.5 的 hack次,但它性能不佳并且缺乏实际的光标移动...

What I'd like to do is use the OVERWRITE caret in INSERT mode. I've seen a hack from .Net 3.5 times, but it is unperformant and lacks behind actual cursor movement...

如果 Caret 有一个模板那就太好了 - 这将与整个 WPF 想法一致...

It would be great if the Caret had a Template - That would be consistent with the whole WPF idea...

有什么建议吗?

推荐答案

CaretElement 是一个内部密封类,无法通过例如数据模板进行自定义.至少,插入符号是可以改变的.

The CaretElement is an internal sealed class and not possible to customize through a data template for example. At least, the caret brush is possible to change.

<TextBox Text="This is some random text" CaretBrush="Blue" />

如果你想在插入符号画笔上有一个线性渐变,这是可以做到的.

If you want to have a linear gradient on the caret brush, this can be done.

<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>

我也尝试使用 Visual Brush,但插入符号总是显示为一条小的垂直线.

I tried using a Visual Brush also, but the caret is always being shown as a small vertical line.

这篇关于文本框插入符号样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆