4

I have a custom TreeView-like control in a panel in my application. As you click on items they receive keyboard focus.

It's possible to select a set of items in the tree and cut or remove them by pressing Ctrl-X or Delete. When the tree items are removed, keyboard focus reverts to the main window.

This leads to trouble - if I Undo my cut, I get my elements back but keyboard focus is no longer on my panel so I can't (for example) go cut-undo-cut-undo-cut.

What determines where the keyboard focus moves when an element is removed? I quickly tried making my panel have IsFocusScope="True" but that didn't seem to have any effect, and the Focus Overview doesn't mention how to control where focus goes when an element is removed.

lilserf
  • 306
  • 1
  • 9

1 Answers1

0

I guess your best bet might be setting the focus manually after undo/redo (maybe encapsulating this in a behavior which listens to the events FocusManager sends?)

See also Set focus on textbox in WPF

Community
  • 1
  • 1
Matthias
  • 12,053
  • 4
  • 49
  • 91