C# 数据绑定图钉

C# 数据绑定图钉,c#,.net,xaml,data-binding,bing-maps,C#,.net,Xaml,Data Binding,Bing Maps,当我在Xaml中为Windows8应用程序传递数据绑定时,提取所需的一些信息时遇到了一些问题 我在app.xaml中设计了一个默认模板: <DataTemplate x:Key="PinTemplate"> <bm:Pushpin Name="{Binding img}" IsTapEnabled="True" > <bm:MapLayer.Position> &

当我在Xaml中为Windows8应用程序传递数据绑定时,提取所需的一些信息时遇到了一些问题

我在app.xaml中设计了一个默认模板:

 <DataTemplate x:Key="PinTemplate">
            <bm:Pushpin Name="{Binding img}" IsTapEnabled="True" >
                <bm:MapLayer.Position>
                    <bm:Location Latitude="{Binding Latitude}" Longitude="{Binding Longitude}" />
                </bm:MapLayer.Position>
            </bm:Pushpin>
 </DataTemplate>
试一试

我通常就是这样做的,因为你并不总是知道发件人的类型,但对我来说,似乎是图钉

 <Maps:Map Name="london" HorizontalAlignment="Left" Height="546" Margin="78,34,0,0" Grid.Row="1"       VerticalAlignment="Top" Width="806" Credentials="{StaticResource BingCredentials}" RenderTransformOrigin="0.439,0.282">
        <Maps:Pushpin Name="myPin" Height="100" Width="100"/>
        <Maps:MapItemsControl ItemTemplate="{StaticResource PinTemplate}" ItemsSource="{Binding PushpinCollection}" Height="100" Width="100" Tapped="pushPin_Tapped"/>
        <Popup VerticalOffset="200"  HorizontalOffset="300" x:Name="Image" IsLightDismissEnabled="True" Height="2000" Width="2000" >
            <Image Name="myImage" Height="300" Width="300" Source="Assets/Logo.png"/>
        </Popup>
    </Maps:Map>
 public class PushpinModel
    {
        public double Longitude { get; set; }
        public double Latitude { get; set; }
        public string img { get; set; }
    }

  public ObservableCollection<PushpinModel> PushpinCollection { get; set; }

  PushpinCollection = new ObservableCollection<PushpinModel>();

        PushpinCollection.Add(new PushpinModel() { Latitude = templat[0], Longitude = templng[0], img = names[0] });
        PushpinCollection.Add(new PushpinModel() { Latitude = templat[1], Longitude = templng[1], img = names[1] });
        DataContext = this;
     private void pushPin_Tapped(object sender, TappedRoutedEventArgs e)
    {
           if (!Image.IsOpen) { Image.IsOpen = true; }
              var pushpinData = (sender as Pushpin).DataContext as PushpinModel;
              String file = pushpinData.ToString();
              // use image in popup here
    }
var pushpinData = (sender as FrameworkElement).DataContext as PushpinModel;