且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式导航WPF UI元素选项卡停靠点?

更新时间:2023-02-04 13:34:11

您可以使用MoveFocus进行操作,如本MSDN文章中所述,该文章解释了有关焦点的所有内容:

You do that using MoveFocus as shown in this MSDN article which explains everything about focus: Focus Overview.

这里有一些示例代码可以到达下一个重点关注的元素(从那篇文章中得到,稍作修改).

Here is some sample code to get to the next focused element (got it from that article, slightly modified).

// MoveFocus takes a TraversalRequest as its argument.
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);

// Gets the element with keyboard focus.
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;

// Change keyboard focus.
if (elementWithFocus != null) 
{
    elementWithFocus.MoveFocus(request);
}