1
votes

I have a Map control showing a few Pushpins. I do not want the user to navigate in the map so I disable it. But I do want the user to be able to tap on a Pushpin (and in the event I navigate to a detail page).

However when the Map.IsEnabled is false, the Pushpins don't seem to receive any gestures either. I've also tried using IsHitTestVisible, but with no luck.

Some code showing what I'm trying to do. Does anyone have any ideas?

<maps:Map Name="Map"
          VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
          CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" ScaleVisibility="Collapsed" ZoomBarVisibility="Collapsed"
          IsEnabled="False">
    <maps:MapItemsControl ItemsSource="{Binding TheCollection}">
        <maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <maps:Pushpin Name="Pin" Location="{Binding Coordinate}" Content="{Binding Ix}">
                    <maps:Pushpin.Background>
                        <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                    </maps:Pushpin.Background>

                    <toolkit:GestureService.GestureListener>
                        <toolkit:GestureListener Tap="PinTap"  />
                    </toolkit:GestureService.GestureListener>
                </maps:Pushpin>
            </DataTemplate>
        </maps:MapItemsControl.ItemTemplate>
    </maps:MapItemsControl>
</maps:Map>
2

2 Answers

1
votes

So here's how I solved it after a lot of testing and browsing MSDN. It turns out that things are a bit different in the Map control on Windows Phone (see MSDN). There are new behaviors and events compared to normal Silverlight.

<maps:Map Name="Map"
          VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
          CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" ScaleVisibility="Collapsed" ZoomBarVisibility="Collapsed"
          MapZoom="Map_MapZoom" MapPan="Map_MapPan">
    <maps:MapItemsControl ItemsSource="{Binding TheCollection}">
        <maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <maps:Pushpin Name="Pin" Location="{Binding Coordinate}" Content="{Binding Ix}">
                    <maps:Pushpin.Background>
                        <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                    </maps:Pushpin.Background>

                    <toolkit:GestureService.GestureListener>
                        <toolkit:GestureListener Tap="PinTap"  />
                    </toolkit:GestureService.GestureListener>
                </maps:Pushpin>
            </DataTemplate>
        </maps:MapItemsControl.ItemTemplate>
    </maps:MapItemsControl>
</maps:Map>

...

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

private void Map_MapZoom(object sender, MapZoomEventArgs e)
{
    e.Handled = true;
}
1
votes

Setting IsEnabled to false prevents the Map control from responding to user input, which affects the child Pushpin as you've seen. If you want the map to be read-only but the Pushpin to respond to gestures then I think you have two options:

  1. Handle all the gesture events on the Map control and set e.Handled to true, which will prevent the Map itself from processing the event, but should leave the PushPin free to handle the tap gesture.
  2. Create a WriteableBitmap of the Map and show that instead, and then display the Pushpin on top (NOTE: I suspect that the Pushpin control won't work outside of the Map control, so you'd need to create/re-template a control to look like a Pushpin).

UPDATE: The events that you need to handle on the Map to make it appear "read-only" but remain enabled are MapPan and MapZoom.