G.Mich
G.Mich

Reputation: 1666

MapItemsControl Tapped Event on WP 8.1 RT

I'm working on Windows Phone 8.1 RT project and i want to get my binding item when mapcontrolSP tapped.

    <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>

I create a tapped event on the StackPanel element but item is null:

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

How can i get item ?

Upvotes: 0

Views: 188

Answers (1)

Arek Kubiak
Arek Kubiak

Reputation: 781

Fast solution:

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();
        }
}

Upvotes: 2

Related Questions