如何以编程方式导航 WPF UI 元素制表位? [英] How to programmatically navigate WPF UI element tab stops?

查看:13
本文介绍了如何以编程方式导航 WPF UI 元素制表位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何以编程方式浏览 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆