wpfbing-mapsbing

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?


Solution

  • 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;
        }
    }