gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:52:01 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com