WPF: KeyboardNavigationMode.Contained doesn't work to suppress focus wrap
- by codymanix
I want to navigate in my window with the arrow key. It works so far but if I reach the end of my window, focus wraps to the first main menu item. But I want that focus stops at the last control in my window.
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down)
{
elem.MoveFocus(FocusNavigationDirection.Next);
}
}
"elem" is indirect child control of "stackPanel". MoveFocus always returns true and I already tried:
KeyboardNavigation.SetTabNavigation(stackPanel, KeyboardNavigationMode.Contained); KeyboardNavigation.SetDirectionalNavigation(stackPanel,KeyboardNavigationMode.Contained);
KeyboardNavigation.SetControlTabNavigation(stackPanel, KeyboardNavigationMode.Contained);
Nothing helped.