如何在Windows Phone上的MapControl中创建可点击的引脚

时间:2016-01-29 09:15:25

标签: c# wpf xaml mvvm prism

我在xaml中有以下代码

<ListView Grid.Row="2" Grid.ColumnSpan="2"  Visibility="{Binding SwitchText}"  ItemsSource="{Binding Path=FilteredRestaurants}" SelectionMode="Single" IsItemClickEnabled="True">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding name}" Style="{StaticResource TextBlockInfoFriTheme}" 
                                    TextWrapping="Wrap" />
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <Interactivity:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="ItemClick">
                                <core:InvokeCommandAction Command="{Binding Path=ShowDetailCommand}" />
                            </core:EventTriggerBehavior>
                        </Interactivity:Interaction.Behaviors>
</ListView>

和一个viewmodel

ShowDetailCommand = new DelegateCommand<ItemClickEventArgs>(async (args) =>
            {
                Restaurant restaurant = args.ClickedItem as Restaurant;
                MessageDialog dialog = new MessageDialog(restaurant.toString());
                await dialog.ShowAsync();
            });

当我点击该项目时,这完全没问题,所以我在地图中尝试了相同的方法并且它起作用了。从我可以谷歌它的问题是我不能在任何地方使用IsItemClickEnabled =“True”所以我的其他选择是什么?因为当我点击图钉时,id喜欢具有相同的功能。

所以这是来自我的其他PivotItem的xaml:

<Maps:MapItemsControl ItemsSource="{Binding FilteredRestaurants}"  >
                        <Maps:MapItemsControl.ItemTemplate>
                            <DataTemplate >
                                <StackPanel 
                            Maps:MapControl.NormalizedAnchorPoint="0.5,1" 
                            Maps:MapControl.Location="{Binding coordinates,Converter={StaticResource CoordinatesToGeopointConverter}}"
                            Width="Auto" Height="Auto"  >

                                <Interactivity:Interaction.Behaviors>
                                    <core:EventTriggerBehavior EventName="ItemClick">
                                        <core:InvokeCommandAction Command="{Binding ShowFoodLocationDetails}" />
                                    </core:EventTriggerBehavior>
                                </Interactivity:Interaction.Behaviors>

                                <Grid x:Name="FoodContentGrid"  Height="Auto" Width="Auto" >
                                    <Rectangle Fill="#FF3FC500" Height="Auto" Width="Auto" RadiusX="3" RadiusY="3"/>
                                    <StackPanel HorizontalAlignment="Center" Margin="5" >
                                        <TextBlock x:Name="FoodLocationName"  Text="{Binding name}" FontSize="14" Foreground="White" HorizontalAlignment="Center" />
                                    </StackPanel>
                                </Grid>
                                <Path Data="M33.4916,35.3059 L42.1937,35.3059 L38.1973,40.6036 z" Fill="#FF3FC500" HorizontalAlignment="Center" Height="6.302" Margin="0,-1,0,0" Stretch="Fill" UseLayoutRounding="False" Width="9.702"/>
                            </StackPanel>
                        </DataTemplate>
                    </Maps:MapItemsControl.ItemTemplate>
                </Maps:MapItemsControl>

所以我非常感谢任何有关如何激活我的同志的建议。 也是一个半相关的问题。是否可以在严格的MVVM架构中使用MapIcon?因为当我在视图后面的代码中使用Maps看起来好多了但是我改变它因为严格的MVVM目前更重要

0 个答案:

没有答案