0

I'm working on a simple map app for windows phone 8. I set multiple pushpins by using windows phone toolkit. I want to show more details info when a pushpin item is tapped. Here is my code.

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <maps:Map Name="MyMap"
                  CartographicMode="Road" ColorMode="Light"
                  LandmarksEnabled="True" PedestrianFeaturesEnabled="True">

            <toolkit:MapExtensions.Children>                    
                <toolkit:MapItemsControl Name="allDatas">
                    <toolkit:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <toolkit:Pushpin GeoCoordinate="{Binding Coordinate}" 
                                             Content="{Binding Name}"            
                                             Background="Green"
                                             Foreground="Black"
                                             Tap="Pushpin_Tap"/>
                        </DataTemplate>
                    </toolkit:MapItemsControl.ItemTemplate>
                </toolkit:MapItemsControl>            
            </toolkit:MapExtensions.Children>

        </maps:Map>
    </Grid> 

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        ObservableCollection<Data> datas = new ObservableCollection<Data>() 
        {
            new Data() { Coordinate = new GeoCoordinate(22.832991,89.539921), Name = "H", Details = "Hospital", Address = "Address of Hospital" },
            new Data() { Coordinate = new GeoCoordinate(22.845489,89.539406), Name = "P", Details = "Fire Station", Address = "Address of Fire"},
            new Data() { Coordinate = new GeoCoordinate(22.818019,89.54563), Name = "F", Details = "Police Station", Address = "Address of Police"}                       
        };

        ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(MyMap);        
        var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;  
        obj.ItemsSource = datas;    
    }

    private void Pushpin_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        Pushpin pushpin = sender as Pushpin;

        if (pushpin.Content != null)
        {   //Here i want to show details
            MessageBox.Show(pushpin.Content.ToString());
        }
    }
Biplob Ahmed
  • 106
  • 4

2 Answers2

0

You can do this:

pushpin.Tap += delegate
{
     if (AppSettings["PushpinOpen"] == true)
     {
           pushpin.Content = attraction.Content;
           AppSettings["PushpinOpen"] = attraction.Title;
           AppSettings.Save();
      }
      else
      {
           pushpin.Content = attraction.Title;
           AppSettings.Remove("PushpinOpen");
       }

  };

You don't have to do it with IsolatedStorageSettings (AppSettings, in this case). You just need to check if the pushpin is already opened, and if it isn't, you can change the content of the pushpin into more detailed information.

user3478148
  • 433
  • 1
  • 8
  • 26
0
private void Pushpin_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var element = (FrameworkElement)sender;
Data data = (Data)element.DataContext;
MessageBox.Show(data.Address);
}

It may be a little bit late, but I tried to achieve the same. Show more data on pushpin Tap. I found a working answer here altought it is an answer for a bit different question.

Community
  • 1
  • 1
papa zulu
  • 317
  • 5
  • 16