是的,我就是这么想的。只需使用
ToolTips
。也许你必须适应
Location
的字符串表示形式转换为所需的坐标格式。这是一个完整的工作示例。
XAML:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
Title="MainWindow" Height="350" Width="525">
<Grid>
<wpf:Map x:Name="myMap" ZoomLevel="5" CredentialsProvider="My Key"
Mode="Aerial" Center="55.852663, -2.3889276"></wpf:Map>
</Grid>
</Window>
代码隐藏:
Imports Microsoft.Maps.MapControl.WPF
Class MainWindow
Public Sub New()
InitializeComponent()
CreatePushPinsWithToolTip()
End Sub
Private Sub CreatePushPinsWithToolTip()
Dim CountyLocations(3) As Location
CountyLocations(0) = New Location(55.852663, -2.3889276)
CountyLocations(1) = New Location(55.956023, -3.1607265)
CountyLocations(2) = New Location(54.840279, -3.2886766)
CountyLocations(3) = New Location(52.819511, -1.8851815)
For index = 0 To CountyLocations.Length - 1
Dim Pin = New Microsoft.Maps.MapControl.WPF.Pushpin()
Dim CoordinateTip As ToolTip = New ToolTip()
CoordinateTip.Content = CountyLocations(index).ToString
Pin.Location = CountyLocations(index)
Pin.ToolTip = CoordinateTip
myMap.Children.Add(Pin)
Next
End Sub
End Class
现在,如果您将鼠标悬停在
PushPin
将显示带有坐标的工具提示。
编辑:
要显示不同的名称,只需创建
Strings
并将其用于创建
Pushpins
和他们的
工具提示
。下面是一个示例:
Private Sub CreatePushPinsWithToolTip()
Dim CountyLocations(3) As Location
CountyLocations(0) = New Location(55.852663, -2.3889276)
CountyLocations(1) = New Location(55.956023, -3.1607265)
CountyLocations(2) = New Location(54.840279, -3.2886766)
CountyLocations(3) = New Location(52.819511, -1.8851815)
Dim names = New String() {"sam", "tom", "leon", "eddy"}
For index = 0 To CountyLocations.Length - 1
Dim Pin = New Microsoft.Maps.MapControl.WPF.Pushpin()
Dim CoordinateTip = New ToolTip()
CoordinateTip.Content = names(index)
Pin.Location = CountyLocations(index)
Pin.ToolTip = CoordinateTip
myMap.Children.Add(Pin)
Next
End Sub