rikkit
rikkit

Reputation: 1137

Disabling pan and zoom events on a Windows Phone map control

I'm developing an app for Windows Phone.

My idea was to display a map on a panorama control - with selected pushpins - which, when pressed, took the user to a larger version of the map.

However, having looked, I can't find a way of disabling the zoom, pan and flick events from the map control. Since this map is only a preview, I don't want to be able to actually use it like a map (but since I want to have pushpins, it still needs to be a map).

Is there any way to disable the gesture events on a map control? Or is there a better way of doing what I want?

Thanks.

Upvotes: 3

Views: 2089

Answers (4)

Branislav
Branislav

Reputation: 11

Try positioning a non-transparent element over the Map with Opacity=0, this works for me:

<Grid>
    <maps:Map x:Name="Map" Height="200" />
    <Grid Height="200" Background="Black" Opacity="0" Tap="MapGrid_OnTap">
        <!--background is black to disable map pan & zoom, if backround is transparent, map still can capture gestures-->
    </Grid>
</Grid>

Upvotes: 1

Qi Luo
Qi Luo

Reputation: 890

void MapControl_MapZoom(object sender, MapZoomEventArgs e)
{
    e.Handled = true;
}

This will prevent the map control zooming by gesture, but the map is still zoomable by the map zoom level bar. So this achieve integral zoom levels for the map control.

Upvotes: 0

vee
vee

Reputation: 755

This is what worked for me on Windows Phone to disable panning.

Add an event handler for MapPan to the Map Control and then in the handler set the event to handled.

private void mapControl_MapPan( object sender, MapDragEventArgs e )
{
  e.Handled = true;
}

This will prevent the Map Control from panning. Should work the same for zoom.

Upvotes: 0

ColinE
ColinE

Reputation: 70122

I recently looked at tackling this problem for the WP7 browser. My solution was to delve into the visual tree, capture the manipulation events and cancel them:

http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/

However, for the Map control I suspect there is a simpler solution. Try positioning a transparent element over the top of the map and using that to capture the manipulation events.

Upvotes: 3

Related Questions