c# - MS UI 自动化 - AddAutomationHandler 未触发

标签 c# .net ui-automation microsoft-ui-automation

我正在使用 Microsoft 的 UI 自动化工具将更改处理程序添加到文本框。代码如下:

            // Get a reference to the textbox.
            var textbox = window.FindFirst(
                TreeScope.Descendants,
                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)
            );


        // Bind a property change handler to the textbox -- this works great
        Automation.AddAutomationPropertyChangedEventHandler(
                textbox,
                TreeScope.Element,
                (o, e) => { Console.WriteLine("Textbox value property event"); },
                ValuePattern.ValueProperty
            );

        //A different way of binding - why doesn't this fire?
        Automation.AddAutomationEventHandler(
                TextPatternIdentifiers.TextChangedEvent, // is this the right event?
                textbox,
                TreeScope.Element,
                (o, e) => { Console.WriteLine("Text Changed Event (I want this to fire please)"); }
            );

每当更改文本框时,Automation.AddAutomationPropertyChangedEventHandler 添加的事件处理程序触发得很好,但是由 Automation.AddAutomationEventHandler 添加的事件处理程序不开火。

我必须在这里监听不同类型的事件吗?那应该是哪个事件?

最佳答案

您是否已使用 AccEvent SDK 工具验证用户界面正在引发 TextChanged 事件?例如,我刚刚运行了 AccEvent,并将其设置为报告记事本引发的 TextChanged 事件。下图显示在我键入时正在引发事件。当您在您正在使用的 UI 中键入时,看看 AccEvent 是否报告事件会很有趣。如果没有引发事件,则不会调用您的处理程序。

谢谢,

家伙

enter image description here

关于c# - MS UI 自动化 - AddAutomationHandler 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32802747/

相关文章:

automation - 是否有任何 RPA(机器人流程自动化)的开源工具

ios - 如何点击表格 UI 自动化中的特定单元格 (Swift)

c# - 不同的值成员,相同的控件

c# - WCF - 客户端端点配置错误

c# - .NET DICOM库

c# - 时间跨度比较

c# - 具有 "implements"限制的更高级接口(interface)

c# - 对象初始化程序强制编译错误

c# - 真正基本的 C# 数组/循环混淆

google-chrome - 如何从 Protractor 自动将浏览器设置为离线?