我有一个派生自WindowsFormsHost
的类,它监听WinForms鼠标事件。它适用于单击,但有没有办法触发双客户端事件? ClickCount
是只读的,因此我无法设置它,并且Control.MouseDoubleClickEvent
无法传播它。还有其他想法吗?
private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
MouseButton? wpfButton = ConvertToWpf(e.Button);
if (!wpfButton.HasValue)
return;
RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, wpfButton.Value) {
RoutedEvent = Mouse.MouseDownEvent,
Source = this
//ClickCount = 2 // read-only
});
//RaiseEvent(new RoutedEventArgs() { // won't propagate
// RoutedEvent = System.Windows.Controls.Control.MouseDoubleClickEvent,
// Source = this
//});
}
答案 0 :(得分:0)
您可以在WPF中以编程方式提出MouseDoubleClickEvent
:
MouseButtonEventArgs doubleClickEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, (int)DateTime.Now.Ticks, MouseButton.Left);
doubleClickEvent.RoutedEvent = Control.MouseDoubleClickEvent;
doubleClickEvent.Source = this;
RaiseEvent(doubleClickEvent);