我希望为每个推针添加一个自定义信息标签,这些标签会在点击时或光标滑过时显示。因为这对我来说是第一次,我想知道如何制作一个非常基本的,并且由于我目前使用VB的代码布局,我宁愿使用VB而不是XAML。
目前,我正在使用循环在地图上实现多个图钉。
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()
Pin.Location = CountyLocations(index)
UserControl11.BingMap.Children.Add(Pin)
Next
Q1。如何在图钉上创建基本信息选项卡(资源材料)
Q2。我如何添加到我当前的代码?
答案 0 :(得分:2)
是的,这就是我的想法。只需使用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
及其ToolTips
的同一循环中使用它。这是一个例子:
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