Problem with TreeScope in Automation.AddAutomationEventHandler
I would like to handle automation events, such as InvokePattern.InvokedEvent. I use the Automation.AddAutomationEventHandler method with different tree scopes (always with the same handler function called MyAutomationEventHandler).
Automation.AddAutomationEventHandler(event, element, scope, new AutomationEventHandler(MyAutomationEventHandler));
The arguments are the AutomationEvent, the AutomationElement, the TreeScope, and the AutoamtionEventHandler delegate.
My problem is the following:
- if I use TreeScope.Element: the handler works perfectly
- if I use TreeScope.Children: nothing happens, the handler method is never called for any children
- if I use TreeScope.Subtree: nothing happens, the handler method is never called for any element of the subtree. But if I add another handler at this time for an element (that is in the former subtree) with TreeScope.Element, then the handler method will be called twice each time when the event occurs for the specific element.
I don't know, what the problem is.
Mark

