PreviewlostkeyboardFocus event fires twice when I click on combobox WPF

835 Views Asked by At

I have wired PreviewLostKeyboardFocus event to TextBox. I handled the event. When I click on the ComboBox control, it fires twice.

If I not handled it fires only one time.

private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    e.Handled = true;
}

Can someone please help resolve this issue ?

1

There are 1 best solutions below

2
On

When you set:

e.Handled = True;

You are effectively preventing the focus leaving the TextBox.

So if focus is in this TextBox and you click on another field (e.g. ComboBox) it will cause the event to fire, but the cursor will remain forever in the TextBox.

Remove this or make it conditional.