WPF提升DoubleClick事件

时间:2018-06-16 18:51:55

标签: c# wpf

我有一个派生自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
    //});
}

1 个答案:

答案 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);