4

In my main application window, there are controls, each of which opens a popup that presents more controls to the user.

Other controls in the main application window have mousedoubleclick event handlers. My problem is that when the a user double clicks in the popup, the controls behind the popup are receiving the mousedoubleclick events.

I've tried added a mousedoubleclick event handler to the popup's parent, and handling the event, but it still gets through to the main application window.

    private void ParentControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        e.Handled = true;
    }

I've also tried invoking Popup.CaptureMouse() in a MouseEnter event handler in the popup, but the method always fails (returns false).

    void popup_MouseEnter(object sender, MouseEventArgs e)
    {
        e.Handled = true;
        Popup popup = sender as Popup;
        bool success = popup.CaptureMouse();
    }

Are there any other ways to prevent the mouse events from firing in the main application window when the popup is open?

4

1 回答 1

-2

简单的!而不是使用控件的MouseDoubleClick事件

private void myControl_MouseDoubleClick(System.Object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    MessageBox.Show("MouseDoubleClick on control");

}

使用PreviewMouseDoubleClick事件。

private void myControl_PreviewMouseDoubleClick(System.Object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    MessageBox.Show("PreviewMouseDoubleClick on control");

}

现在双击您的控件也不会调用父级的 DoubleClick 事件。

于 2011-07-04T12:20:39.527 回答