如何在 WP 8.1 RT 上访问 MapItemsControl 中的元素?
How to access element in MapItemsControl on WP 8.1 RT?
我正在处理 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 的信息,我在图像元素上创建了一个点击事件:
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;
}
pin 的信息显示很好,但是当我重新录音时,我想隐藏以前的 pin 的信息并显示新的。
如何浏览 MapItemsControl 元素以隐藏所有图钉信息?
好吧,您可以将 bool(或可见性)属性 添加到您的 ViewStoreModel.loc2 数据模型中并将其绑定到 DisplayInformation 的可见性。然后,在您的 Image_Tapped 中,将所有设置为 false,并在 s.DataContext(您绑定的项目存储在哪里)中将此 属性 设置为 true。
我正在处理 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 的信息,我在图像元素上创建了一个点击事件:
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;
}
pin 的信息显示很好,但是当我重新录音时,我想隐藏以前的 pin 的信息并显示新的。
如何浏览 MapItemsControl 元素以隐藏所有图钉信息?
好吧,您可以将 bool(或可见性)属性 添加到您的 ViewStoreModel.loc2 数据模型中并将其绑定到 DisplayInformation 的可见性。然后,在您的 Image_Tapped 中,将所有设置为 false,并在 s.DataContext(您绑定的项目存储在哪里)中将此 属性 设置为 true。