Is there a way to make the caret in a textbox visible even when the textbox has lost focus?
Asked
Active
Viewed 2,786 times
2 Answers
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;
}

kevinarpe
- 20,319
- 26
- 127
- 154
-
I couldn't get IsFocusScope to work at all so I tried this. It nearly works, the caret remains visible, but it no longer flashes. I'd really like to find a way to retain the flashing caret. – Dave Jan 25 '22 at 16:29
-
I did find a way - I used the PreviewLostKeyboardFocus event instead of the LostFocus event, but that's not ideal either as no other controls can get the focus. I've only got one textbox in the view so it might be ok. – Dave Jan 25 '22 at 16:50
2
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"

iyalovoi
- 191
- 1
- 5