MapItemsControl在WP 8.1 RT上被选中的事件

本文关键字:事件 RT WP MapItemsControl | 更新日期: 2023-09-27 18:13:32

我正在Windows Phone 8.1 RT项目上工作,我想在mapcontrolSP点击时获得我的绑定项。

    <Maps:MapControl x:Name="Map" MapServiceToken="abcdef-abcdefghijklmno">
        <Maps:MapItemsControl x:Name="mapitem" ItemsSource="{Binding}">
            <Maps:MapItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel x:Name="mapcontrolSP" Orientation="Horizontal" Background="Red" Tapped="ItemStckPanel">
                        <Image Source="Assets/ico-venue.png" Height="45" Width="45"
                           Maps:MapControl.Location="{Binding Geopoint}"
                           Maps:MapControl.NormalizedAnchorPoint="{Binding Anchor}"/>
                        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5">
                            <TextBlock FontSize="15" Foreground="White" Text="{Binding name}"/>
                            <TextBlock FontSize="15" Foreground="White" Text="{Binding address}"/>
                            <TextBlock FontSize="15" Foreground="White" Text="{Binding distance}"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </Maps:MapItemsControl.ItemTemplate>
        </Maps:MapItemsControl>
    </Maps:MapControl>

我在StackPanel元素上创建了一个tap事件,但是item为null:

    private void ItemStckPanel(object sender, TappedRoutedEventArgs e)
    {
            var item = sender as FsqBasicItem;
            MessageDialog dialog = new MessageDialog(item.name);
            dialog.ShowAsync();
    }

如何获取item

MapItemsControl在WP 8.1 RT上被选中的事件

快速解:

private void ItemStckPanel(object sender, TappedRoutedEventArgs e)
{
        var stackPanel = sender as StackPanel;
        var item = stackPanel.DataContext as FsqBasicItem;
        if(item != null)
        {
            MessageDialog dialog = new MessageDialog(item.name);
            dialog.ShowAsync();
        }
}