2010-10-11 80 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