How should I handle click events on pushpins in my Bing Maps control for WP7

前端 未结 3 899
醉梦人生
醉梦人生 2021-01-25 05:32

I\'m about to add templated

相关标签:
3条回答
  • 2021-01-25 05:40

    If all you want is to be able to click/tap on each pushpin, add a MouseLeftButtonUp event to each pushpin you create. For example:

    Microsoft.Phone.Controls.Maps.Pushpin pp = null;
    System.Device.Location.GeoCoordinate loc = null;
    
    pp = new Microsoft.Phone.Controls.Maps.Pushpin();
    loc = new System.Device.Location.GeoCoordinate([Latitude], [Longitude]);
    
    pp.Location = loc;
    pp.Content = "Some Content";
    pp.MouseLeftButtonUp += new MouseButtonEventHandler(Pushpin_MouseLeftButtonUp);
    

    then you add

    void Pushpin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
         Microsoft.Phone.Controls.Maps.Pushpin tempPP = new Microsoft.Phone.Controls.Maps.Pushpin();
    
         tempPP = (Microsoft.Phone.Controls.Maps.Pushpin)sender;
    
         // you can check the tempPP.Content property
    
    } 
    
    0 讨论(0)
  • 2021-01-25 05:54

    Why dont you add an Invisible styled button inside the MapItemsControl.ItemTemplate and use Click on the button.

    0 讨论(0)
  • 2021-01-25 05:59

    MouseLeftBUttonUp ? I have only the emulator and it works on my custom pushpin :

    <Maps:MapItemsControl ItemsSource="{Binding Stores}">
                    <Maps:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Maps:Pushpin Location="{Binding Location}" MouseLeftButtonUp="Pushpin_MouseLeftButtonUp">
                                <Maps:Pushpin.Template>
                                    <ControlTemplate TargetType="Maps:Pushpin">
                                        <Border BorderBrush="Black" BorderThickness="1" Background="MintCream" Width="32" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center">
                                            <TextBlock Text="{Binding Store.Address}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        </Border>
                                    </ControlTemplate>
                                </Maps:Pushpin.Template>
                            </Maps:Pushpin>
                        </DataTemplate>
                    </Maps:MapItemsControl.ItemTemplate>
                </Maps:MapItemsControl>
    

    Edit: After getting a real device I have tested my application and I can confirm that MouseLeftBUttonUp is a bad idea (and not recommended by Microsoft in the Performance tips)

    instead you sould use Manipulation events:

    <Maps:MapItemsControl ItemsSource="{Binding Stores}">
    <Maps:MapItemsControl.ItemTemplate>
        <DataTemplate>
            <Maps:Pushpin Location="{Binding Location}" ManipulationStarted="Pushpin_ManipulationStarted">
                <Maps:Pushpin.Template>
                    <ControlTemplate TargetType="Maps:Pushpin">
                        <Image Width="48" Height="48" Source="{Binding InventoryIcon}" />
                    </ControlTemplate>
                </Maps:Pushpin.Template>
            </Maps:Pushpin>
        </DataTemplate>
    </Maps:MapItemsControl.ItemTemplate>
    </Maps:MapItemsControl>
    
    0 讨论(0)
提交回复
热议问题