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?