Topics

Subscribing to UIAutomation events

Karl-Otto Rosenqvist
 

Hi!
It's me with the UIA DataGrid again...
Now they've added events to the UIA DataGrid and I'm able to subscribe to it from C# as follows:

Automation.AddAutomationEventHandler(
SelectionPattern.InvalidatedEvent,
grid,
TreeScope.Element,
UIAeventHandler = new AutomationEventHandler(OnUIAutomationEvent)
);

And then unsubscribe like this:
if (UIAeventHandler != null)
{
Automation.RemoveAutomationEventHandler(
SelectionPattern.InvalidatedEvent,
grid,
UIAeventHandler
);
} // if

The method that's getting called when the event is raised looks like this:
private static void OnUIAutomationEvent(object src, AutomationEventArgs e)
{
// Make sure the element still exists. Elements such as tooltips
// can disappear before the event is processed.
AutomationElement sourceElement;
try
{
sourceElement = src as AutomationElement;
}
catch (ElementNotAvailableException)
{
return;
}

if (e.EventId == SelectionPattern.InvalidatedEvent)
{
try
{
Console.WriteLine("--- Markering ---");
var s = grid.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
foreach (var c in s.Current.GetSelection())
{
var v = c.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
System.Console.WriteLine(v.Current.Value);
} // foreach

}
catch (Exception ex)
{
Console.WriteLine("Fel när markerad rad hämtades");
Console.WriteLine(ex.Message);
}

} // if

}


I have the following questions:

1. How do I subscribe to an UIA event in an app m module? I will create a class for the specific UIA element type.

2. How do I get hold of the Selection pattern and the Value patterns for an UIA element? When trying to get hold of the UIASelectionPattern NVDA says that it isn't implemented. The UIASelectionItemPattern is shown when I do a dir(nav) in the Python console but that pattern isn't implemented by the DataGrid.

It seems so close because I can hook up the grid event and print the selection to the console in C# but not in Python. Can anyone point me in the right direction?


Best regards

Karl-Otto

--
Karl-Otto Rosenqvist
Mawingu
Orgnr: 750804-3937
0701- 75 98 56
karl-otto@...
https://mawingu.se