WPF Textbox persist visible caret

旧巷老猫 提交于 2019-12-13 13:58:15

问题


Is there a way to make the caret in a textbox visible even when the textbox has lost focus?


回答1:


Maybe this is not you want, but i have used it. Actually you can set FocusManager.IsFocusScope="True" on your textbox, so it will always has focus it's own focus. It means caret will be always visible. You can enable/disable such behaviour FocusManager.IsFocusScope="True"/"False"




回答2:


Here is another way. The selection will also remain highlighted.

private void MyMethod()
{
    TextBox txt = ...;
    txt.LostFocus += new RoutedEventHandler(staticTextBox_LostFocus);
}

private static void staticTextBox_LostFocus(object sender, RoutedEventArgs e)
{
    e.Handled = true;
}


来源:https://stackoverflow.com/questions/2859988/wpf-textbox-persist-visible-caret

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!