简体   繁体   English

C#UI自动化:Current.Name返回空字符串

[英]C# UI Automation: Current.Name returns empty string

I want to use System.Windows.Automation in my C# program to report Name property on FocusChangedEvent just like AccEvent.exe does. 我想在C#程序中使用System.Windows.Automation来报告FocusChangedEvent的Name属性,就像AccEvent.exe一样。

I have a simple console app which should display the name of the sender whenever FocusChangedEvent is fired: 我有一个简单的控制台应用程序,每当触发FocusChangedEvent时,该应用程序都应显示发件人的名称:

Automation.AddAutomationFocusChangedEventHandler((sender, e) => {
    AutomationElement element = sender as AutomationElement;
        if (element != null)
            {
                Console.WriteLine(element.Current.Name);
            }
        });

This mostly works as I expected. 这主要是我所期望的。 Switching my focus between windows and elements within windows shows the name of the focused element. 在窗口和窗口中的元素之间切换我的焦点将显示焦点元素的名称。 However for a lot of elements the Name property returns empty string ("") . 但是,对于许多元素,Name属性返回空字符串(“”)

Checking with AccEvent.exe (UIA FocusEvent), the sender name displays fine for the same elements. 使用AccEvent.exe(UIA FocusEvent)进行检查,对于相同的元素,发件人名称显示良好。

How to troubleshoot this? 如何解决这个问题? Any direction would be appreciated. 任何方向将不胜感激。

I switched to UIAComWrapper in my project and now my results are consistent with AccEvent and it also feels much faster. 我在项目中切换为UIAComWrapper,现在我的结果与AccEvent一致,而且感觉也更快。

Differences between UIAComWrapper and UIAutomationClient are stated in another SO question: Difference between UIaComWrapper and UIAutomationCLient + UIAutomationType UIAComWrapper和UIAutomationClient之间的差异在另一个SO问题中有所说明: UIaComWrapper和UIAutomationCLient + UIAutomationType之间的差异

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM