2010-10-11 55 views
13

有没有办法将光标隐藏在WPF文本框中?我知道有光标=“无”,但只影响鼠标光标。我想隐藏“文本光标”。在WPF文本框中隐藏插入符号

+2

相关:http://stackoverflow.com/questions/935769/wpf-passwordbox-caret – 2010-10-11 20:49:29

+0

谢谢,工作。 – 2010-10-11 21:08:10

回答

6

插入符号是文本编辑器中的当前插入位置。光标是鼠标光标的形状。

无法在读写文本框中禁用插入符号。相反,将CaretBrush更改为透明。

TextBox txt = ...; 
// Hide the caret. 
txt.CaretBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); 
// Show the caret. 
txt.CaretBrush = null; // use default Brush 
8

使用TextBox.CaretBrush属性,可以使光标的颜色与背景颜色相同或Transparent