WPF: KeyboardNavigationMode.Contained doesn't work to suppress focus wrap

Posted by codymanix on Stack Overflow See other posts from Stack Overflow or by codymanix
Published on 2009-09-12T22:53:22Z Indexed on 2010/05/08 12:08 UTC
Read the original article Hit count: 403

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#