WPF - 通过 DataGridCell 上的 AutomationPeer 进行 MouseDown
我有以下代码,可在 DataGridCell 上引发 MouseLeftButtonDownEvent。
DataGridCell dataGridCell = cell as DataGridCell;
MouseButtonEventArgs someEventArgs =
new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
someEventArgs.RoutedEvent = DataGridCell.MouseLeftButtonDownEvent;
dataGridCell.RaiseEvent(someEventArgs);
它工作正常,并且单元格被选中。然而,我现在尝试使用 AutomationPeer 做同样的事情,但我还没有找到一种方法来做同样的事情。
是否可以使用 AutomationPeers 来做到这一点?如果是,我该怎么做?
注意:我需要它来引发 MouseDownEvent,而不是 Click 事件。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答是否定的:
AutomationPeer 类的存在是为了允许 WPF 类实现 UIAutomation 相关的接口,以便 UIAutomation 客户端 - 例如。屏幕阅读器和高级自动化 UI 测试可以使用它们。这些接口通常比鼠标或键盘输入更高级别,而是处理选择或选定状态等概念。
因此,如果某些测试代码使用 UIAutomation 的 InvokeProvider.Invoke() 方法按下按钮,则 AutomationPeer 即使在按钮上也会引发 Click,因此就像按下按钮一样,但不会有任何鼠标或键盘涉及输入 - 没有鼠标事件,也没有键盘事件。
一般来说,UIAutomation 用于自动化其他应用程序,而 ...Peer 类仅用于向 UIAutomation 基础结构公开功能;在您自己的代码中实际调用这些类的情况非常罕见。
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.