Search code examples
c#listviewmvvmkeyboard-shortcutsevent-bubbling

Block the keyboard shortcut "Backspace" when a text filter is in edition and removing characters


In an app I'm working on there is a homemade CustomListView control that I cannot modify.

In the same view there is a Button with a Keyboard shortcut "Backspace" to come back to the previous view.

The problem is that on the CustomListView in the header there are filters text area to allow to filter the ListView content and if I want to remove a character in the ListView filter --> it triggers the Keyboard shortcut of the back to previous view button (Key = Backspace). How can I block the button keyboard shortcut "Backspace" when I remove a character in one of the head filters of the CustomListView and allow it the rest of time ?

I tried :

  • "ListView.IsKeyboardFocusWithin" : KO
  • "ListView.IsKeyboardFocused" : KO
  • "ListView.IsInputMethodEnable" : KO

Thanks per advance for your answer.


Solution

  • You could check if the event originated from a text box & set the flag to stop it bubbling up any further...

    if (e.OriginalSource is TextBox)
    {
        e.Handled = true;
        return;
    }