如何以编程方式导航WPF UI元素选项卡停靠点? [英] How to programmatically navigate WPF UI element tab stops?
问题描述
有人可以告诉我如何以编程方式浏览WPF应用程序中的所有UI元素选项卡吗?我想从第一个制表位开始嗅探相应的元素,访问下一个制表位,嗅探相应的元素,依此类推,直到到达最后一个制表位.
Can anyone tell me how to programmatically navigate through all UI element tab stops in a WPF application? I want to start with the first tab stop sniff the corresponding element, visit the next tab stop, sniff the corresponding element, and so on until I reach the last tab stop.
谢谢, -迈克
推荐答案
您可以使用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);
}
这篇关于如何以编程方式导航WPF UI元素选项卡停靠点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!