问题
I'm developing an UI Automation application for Microsoft Word and I need to catch, for a RichEdit text box, the "AutoAddAutomationPropertyChanged" Event via a specific handler through method "AddAutomationPropertyChangedEventHandler". I have my AutomationElement "element" that represents the RichEdit control and I added the event on my class:
Automation.AddAutomationPropertyChangedEventHandler(element, TreeScope.Subtree, OnPropertyChanged, new[] { ValuePattern.ValueProperty });
and my handler is:
private void OnPropertyChanged(object sender, AutomationPropertyChangedEventArgs e)
{
if (e.Property == ValuePattern.ValueProperty)
{
...code...
}
}
The problem is that if I execute this code on a RichEdit of type "RichEdit20W" it works and it catches the event, entering into OnPropertyChanged handler method. My problem is execute this code on a RICHED60W text control: it seems that the event is never triggered from Richedit60w text control so I cannot catch it to execute my handler code.
For example, with Microsoft Word 2010, if I execute this code using the RichEdit control of the window "Find&Replace", it works and the handler code is executed. Contrarily, if I execute the code using the RichEdit text control on the left of main Word application window, which is a RICHEDIT60W ("Navigation" pane, opened with CTRL + F, and I used Inspect.exe tool to check it), it does not work and the handler code is never executed. I'm very confused because if I try to catch the same property value changed event on RICHEDIT60W with Accevent.exe tool supplied by Windows SDK, the tool works properly and displays the event information.
I tried everything, even with TreeScope.Element and TreeScope.Children parameters on method, but nothing happens.
I follow this: http://msdn.microsoft.com/en-us/library/system.windows.automation.valuepattern.valueproperty(v=vs.110).aspx
to check if the element supports value pattern (obviously it supports...), and this:
set text on textfield / textbox with the automation framework and get the change event
Thanks in advance and sorry for my English.
来源:https://stackoverflow.com/questions/22410643/microsoft-ui-automation-valuepattern-not-supported-for-richedit60w