我正在为 Windows 商店应用程序使用 bing maps sdk。我试图在单击图钉后立即显示标注。我该怎么做?我知道我需要一个自定义控件,但最好有代码来做。我在哪里可以找到一个例子?
谢谢你!
我正在为 Windows 商店应用程序使用 bing maps sdk。我试图在单击图钉后立即显示标注。我该怎么做?我知道我需要一个自定义控件,但最好有代码来做。我在哪里可以找到一个例子?
谢谢你!
将弹出窗口包含为地图控件的子项。
<!-- Map Control -->
<map:Map x:Name="map" Credentials="{StaticResource BingCredentials}"
ShowScaleBar="True"
ShowNavigationBar="False"
ShowBreadcrumb="False"
LogoPosition="TopRight"
ViewRestriction="OneWorldOnly"
Loaded="Map_Loaded"
PreloadArea="Medium">
<!-- pins -->
<map:MapLayer x:Name="mapPinLayer" Visibility="Visible">
<map:MapItemsControl x:Name="mapPins" ItemsSource="{Binding}">
<map:MapItemsControl.ItemTemplate>
<DataTemplate>
<map:Pushpin IsTapEnabled="True" Style="{StaticResource PushPinStyle}" map:MapLayer.Position="{Binding Location}" Tag="{Binding}" Tapped="Pushpin_Tapped" />
</DataTemplate>
</map:MapItemsControl.ItemTemplate>
</map:MapItemsControl>
</map:MapLayer>
<!-- pin popup -->
<Popup x:Name="PushpinPopup" IsLightDismissEnabled="True" DataContext="{Binding}" Tag="{Binding}">
<Border BorderBrush="#F08D45" BorderThickness="1">
<Grid Background="White" Width="300" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Background="#F08D45">
<TextBlock Grid.Row="0" Foreground="White" FontSize="16" FontWeight="Bold" Text="{Binding Name}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10" />
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="15">
<StackPanel Orientation="Horizontal" Visibility="{Binding Telephone, Mode=OneWay, Converter={StaticResource StringToVisibility}}">
<TextBlock Text="Tel" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" FontSize="12" />
<TextBlock Text="{Binding Telephone}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" FontSize="12" />
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding Fax, Mode=OneWay, Converter={StaticResource StringToVisibility}}">
<TextBlock Text="Fax" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" FontSize="12" />
<TextBlock Text="{Binding Fax}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" FontSize="12" />
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding Email, Mode=OneWay, Converter={StaticResource StringToVisibility}}">
<TextBlock Text="Email" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" FontSize="12" />
<HyperlinkButton Content="{Binding Email}" NavigateUri="{Binding EmailMailTo}" HorizontalAlignment="Left" ClickMode="Press"
VerticalAlignment="Center" Margin="5" FontSize="12" Foreground="#F08D45" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="buttonGetDirections" Click="buttonGetDirections_Click">Get Directions</Button>
<Button x:Name="buttonShowServices" Click="buttonShowServices_Click" Tag="{Binding}">Services</Button>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</Popup>
</map:Map>
然后处理图钉点击事件:
private void Pushpin_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
Pushpin p = sender as Pushpin;
if (p != null && p.Tag != null)
{
PushpinModel model = p.Tag as PushpinModel;
if (model != null) ShowPushpinContent(model);
}
}
private void ShowPushpinContent(PushpinModel model)
{
PushpinPopup.IsOpen = false;
PushpinPopup.DataContext = model;
PushpinPopup.IsOpen = true;
MapLayer.SetPosition(PushpinPopup, model.Location);
currentmodel = model;
}