0
votes

I am building application in Silverlight and in this moment I have problem with events. In application I have to draw polygons, where for each polygon

polygon.MouseLeftButtonUp += MouseButtonEventHandler_MouseLeftButtonUp;
polygon.MouseRightButtonUp += MouseButtonEventHandler_MouseRightButtonUp;

Where on mouse left button event should be add image on the place where it is clicked, and on mouse right event should be displayed context menu with single menu item. On menu item click should be displayed some short info.

And this is place where I have problem. When I click on some item from context menu and if that menu item is still over polygon code detect also Mouse left button event and add image.

I would like to do not add image when menu item is clicked, just to show short info.

Any help, advice?

1

1 Answers

0
votes

When wiring up the mouse button events, the MouseButtonEventHandler has MouseButtonEventArgs which will allow you to determine what mouse button was clicked:

private void MouseButtonDownHandler(object sender, MouseButtonEventArgs e)
{
    Control src = e.Source as Control;

    if (src != null)
    {
        switch (e.ChangedButton)
        {
            case MouseButton.Left:
                // do something
                break;
            case MouseButton.Middle:
                // do something
                break;
            case MouseButton.Right:
                // do something
                break;
            case MouseButton.XButton1:
                // do something
                break;
            case MouseButton.XButton2:
                // do something
                break;
            default:
                break;
        }
    }
}

In your case, when you detect that the right mouse button was clicked with the left mouse button handler, cancel the event. And vice versa for the left mouse button handler.