C# 获取数据绑定项中的当前项
我正在向绑定到数据源的映射添加一些推送pingC# 获取数据绑定项中的当前项,c#,windows-phone-7,C#,Windows Phone 7,我正在向绑定到数据源的映射添加一些推送ping <my:Map Height="340" HorizontalAlignment="Left" Margin="12,100,0,0" Name="settingsmap" VerticalAlignment="Top" Width="438" CredentialsProvider="_"> <my:MapItemsControl Name="settingsMapItemControl"
<my:Map Height="340" HorizontalAlignment="Left" Margin="12,100,0,0" Name="settingsmap" VerticalAlignment="Top" Width="438" CredentialsProvider="_">
<my:MapItemsControl Name="settingsMapItemControl" MouseLeftButtonDown="settingsMapItemControl_MouseLeftButtonDown">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:Pushpin Location="{Binding location}">
</my:Pushpin>
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>
图钉绑定到dataitem的“位置”成员
现在,当有人单击pin(或在手机中触摸)时,如何获取绑定到pin的项目(从绑定到地图的对象列表中)?
我想基本上得到的项目,以便我可以显示其他信息,如名称等在屏幕底部。或者说,如果您使用的是MVVM,那么您可以选择“xyz”,在图钉上放置一个EventTrigger和一个InvokeCommandAction,并将DataContext本身绑定到命令参数
<my:Pushpin Location="{Binding location}">
<i:Interactivity.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding PushpinClick}"
CommandParameter="{Binding}" />
</i:EventTrigger>
<i:Interactivity.Triggers>
</my:Pushpin>
只需在虚拟机中使用名为PusphinClick的ICommand,就可以在Execute
如果您不使用MVVM,那么它会变得有点棘手-尝试将MouseLeftButtonDown事件处理程序连接到图钉。在事件处理程序中,您可以通过获取
(发送方作为图钉)来获取“数据”。DataContext
作为您的DataItem…(发送方作为图钉)。DataContext=>null是DataContext null还是发送方不是图钉?因为如果图钉没有DataContext,那么{Binding location}
也不应该工作(除非你是在暗箱操作而不告诉我们。。。