Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS UI Automation- AddAutomationHandler not firing

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?

like image 942
Jeff Avatar asked Mar 15 '23 16:03

Jeff


1 Answers

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

enter image description here

like image 52
Guy Barker - Microsoft Avatar answered Mar 17 '23 07:03

Guy Barker - Microsoft