如何在WP 8.1 RT上访问MapItemsControl中的元素?

时间:2015-03-27 14:36:19

标签: c# xaml windows-phone-8.1 bing-maps

我正在使用Windows Phone 8.1 RT项目,我希望在点按图钉时显示信息。

<Maps:MapControl 
        Center="{Binding ViewStoreModel.loc, Converter={StaticResource GeoPointConvertCenter}}"
        x:Name="Map" 
        HorizontalAlignment="Right" Margin="0,101,0,0" 
        VerticalAlignment="Top" 
        Height="539"  Width="400"
        ZoomLevel = "8"
        LandmarksVisible = "True"
        TrafficFlowVisible = "True"
        PedestrianFeaturesVisible = "False"
        MapServiceToken="{StaticResource MapServiceTokenString}"  >
        <Maps:MapItemsControl x:Name="MapIcons" ItemsSource="{Binding ViewStoreModel.loc2}"  >
            <Maps:MapItemsControl.ItemTemplate>
                <DataTemplate x:Name="Temp">
                    <StackPanel Tapped="Image_Tapped" x:Name="MyStack"  Maps:MapControl.Location="{Binding Geopoint, Converter={StaticResource GeoPointConvertCenter}}" 
                                Maps:MapControl.NormalizedAnchorPoint="{Binding Anch, 
                                Converter={StaticResource NormalizedAnchorPointConverter}}">
                        <Image x:Name="MyImage" Source="{Binding BitmapImage}" />
                        <TextBox x:Name="DisplayInformation" Text="Adress" Visibility="Collapsed"/>
                    </StackPanel>

                </DataTemplate>
            </Maps:MapItemsControl.ItemTemplate>
        </Maps:MapItemsControl>

    </Maps:MapControl>

为了显示pin的信息,我在image元素上创建了一个tapped事件:

        private void Image_Tapped(object sender, TappedRoutedEventArgs e)
    {

        StackPanel s = sender as StackPanel;
        TextBox text = s.FindName("DisplayInformation") as TextBox;
        text.Visibility = Windows.UI.Xaml.Visibility.Visible;
    }

该信息的信息显示效果很好,但是当我重新录制时,我想要隐藏上一个信息并显示新信息。

如何浏览MapItemsControl元素以隐藏所有pin的信息?

1 个答案:

答案 0 :(得分:0)

好吧,您可以将bool(或Visibility)属性添加到ViewStoreModel.loc2数据模型中,并将其绑定到DisplayInformation的可见性。然后,在您的Image_Tapped中,将all设置为false并在s.DataContext中(存储绑定项的位置)将此属性设置为true。