Jana Andropov
Jana Andropov

Reputation: 139

Disable double click Bing Map WPF control

The default behaviour of double clicking the wpf bing map control is to zoom in. I have a map layer of path objects that respond to double clicks. I would prefer that the map control stop handling this event. Is there a way to disable the mouse double click handler on the wpf bing map control?

Upvotes: 0

Views: 238

Answers (2)

thumbmunkeys
thumbmunkeys

Reputation: 20764

You can mark the double click event as "Handled" in the preview event handler to keep it from further being processed:

 myMap.PreviewMouseDoubleClick += (s, e) =>
 {
     e.Handled = true;
 };

Upvotes: 1

rbrundritt
rbrundritt

Reputation: 17964

You will need to monitor the zoom level when the map expects a double click is occuring using the PreviewMouseDoubleClick event. When this event fires, you will want to capture the current zoom level and monitor the ViewChangeOnFrame event. Then ViewChangeOnFrame fires you will set the maps zoom level to the last captured zoom level. You also will then want to monitor the MouseUp event which will remove the ViewChangeOnFrame event.

private double zoom;

MyMap.PreviewMouseDoubleClick += (s, e) =>
{
    zoom = MyMap.ZoomLevel;
    MyMap.ViewChangeOnFrame += MyMap_ViewChangeOnFrame;
};

MyMap.MouseUp += (s, e) =>
{
    MyMap.ViewChangeOnFrame -= MyMap_ViewChangeOnFrame;
};

private void MyMap_ViewChangeOnFrame(object sender, MapEventArgs e)
{
    if (MyMap.ZoomLevel != zoom)
    {
        MyMap.ZoomLevel = zoom;
    }
}

Upvotes: 2

Related Questions