Question

I've got the following code that raises the MouseLeftButtonDownEvent on a DataGridCell.

DataGridCell dataGridCell = cell as DataGridCell;
MouseButtonEventArgs someEventArgs = 
    new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
someEventArgs.RoutedEvent = DataGridCell.MouseLeftButtonDownEvent;
dataGridCell.RaiseEvent(someEventArgs);

It works fine, and the cell is selected. However I am now trying to do the same thing using an AutomationPeer, but I have not been able to find a way to do the same thing.

Is it possible to do it using the AutomationPeers? If yes, how do I do it?

note: I need it to raise a MouseDownEvent, not a Click event.

Thanks

Was it helpful?

Solution

Short answer is no:

AutomationPeer classes exist to allow WPF classes to implement the UIAutomation-related interfaces, so that UIAutomation clients - eg. screenreaders and high(ish)-level automated UI testing can use them. These interfaces are generally higher-level than mouse or keyboard input, and instead deal in concepts like selection or selected state instead.

So if some test code uses UIAutomation's InvokeProvider.Invoke() method to press a button, the AutomationPeer will raise a Click even on the button, so it will be as through the button was pressed, but there won't be any mouse or keyboard input involved - no mouse events, and no keyboard events.

Generally speaking, UIAutomation is used to automate other apps, and the ...Peer classes are used only to expose functionality to the UIAutomation infrastructure; it's very rare to actually call those classes in your own code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top