Where does the keyboard focus go when the focused WPF element is removed?

I have my own TreeView control in a panel in my application. When you click on items, they get keyboard focus.

You can select a set of elements in the tree and cut or delete them by pressing Ctrl-X or Delete. When the elements of the tree are deleted, the keyboard focus returns to the main window.

This leads to trouble - if I cancel my crop, I will return my elements, but the keyboard focus is no longer on my panel, so I can’t (for example) go cut-cancel-cut-cancel.

What determines when the keyboard focus moves when an item is deleted? I quickly tried to make my panel IsFocusScope = "True", but this did not show any effect, and Focus Review does not mention how to control focus when deleting an element.

+4
source share
1 answer

I believe the best option would be to manually set focus after undo / redo (maybe encapsulating this in a behavior that listens for events FocusManagersends?)

See also Set focus to text field in WPF

0
source

Source: https://habr.com/ru/post/1622986/


All Articles