I'm using Microsoft's UI Automation tools to add change handlers to a textbox. The code is below:
// 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)"); }
);
Whenever the textbox is changed, the event handler added by Automation.AddAutomationPropertyChangedEventHandler
fires just fine, but the event handler added by Automation.AddAutomationEventHandler
does not fire.
Do I have to listen for a different type of event here? Which event should that be?
Have you verified with the AccEvent SDK tool that the TextChanged events are being raised by the UI? For example, I just ran AccEvent, and set it up to report TextChanged events being raised by Notepad. The image below shows that the events are being raised as I type. It would be interesting to see if AccEvent reports the events as you type in the UI that you're working with. If the events aren't being raised, then your handler won't be called.
Thanks,
Guy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With