您可以尝试处理SelectionChanged的事件TextBox。
在 XAML 中,您可以这样定义文本框:
<TextBox x:Name="myTextBox" SelectionChanged="TextBox_SelectionChanged" />
Run Code Online (Sandbox Code Playgroud)
接下来,编写处理光标更改的方法:
private void TextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
int caretPosition = myTextBox.CaretIndex;
//put your handling code here...
}
Run Code Online (Sandbox Code Playgroud)
它会在每次插入符更改时触发,因此在获得焦点、使用箭头键移动光标、使用鼠标更改光标位置等时触发。
如果您需要在多个文本框中执行此行为,您也可以基于此创建您自己的类TextBox,并以类似的方式创建您自己的事件。
我已经在 WPF 项目中对此进行了测试,但它也应该适用于 Silverlight 项目。
| 归档时间: |
|
| 查看次数: |
7886 次 |
| 最近记录: |