WPF:KeyboardNavigationMode.Contained 无法抑制焦点换行
我想用箭头键在窗口中导航。到目前为止它可以工作,但如果我到达窗口的末尾,焦点就会回到第一个主菜单项。但我希望焦点停止在窗口中的最后一个控件上。
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down)
{
elem.MoveFocus(FocusNavigationDirection.Next);
}
}
“elem”是“stackPanel”的间接子控件。 MoveFocus 总是返回 true,我已经尝试过: KeyboardNavigation.SetTabNavigation(stackPanel, KeyboardNavigationMode.Contained); KeyboardNavigation.SetDirectionalNavigation(stackPanel,KeyboardNavigationMode.Contained); KeyboardNavigation.SetControlTabNavigation(stackPanel, KeyboardNavigationMode.Contained);
没有任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 TraversalRequest 实例怎么样?
请注意,TraversalRequest.Wrapped 的 MSDN 文档 表示默认情况下它是 false,因此焦点无论如何都不应该换行。
How about using a TraversalRequest instance?
Mind you, the MSDN documentation for TraversalRequest.Wrapped says that it's false by default, so the focus shouldn't wrap anyway.