我正在我的应用程序中使用WPF Bing地图并且它当前设置为以某纬度经度为中心,我想知道如果不是设置纬度经度而是我可以显示文本框和搜索按钮在哪里用户可以输入所选位置的纬度经度。如果是这样,我应该添加什么代码?
的Xaml
Title="MainWindow" Height="320.149" Width="475.746">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<m:Map CredentialsProvider="My Key" Mode="AerialWithLabels"
Center="51.521347, -0.138983" ZoomLevel="16" x:Name="BingMap" Grid.ColumnSpan="2">
<TextBox x:Name="txtwhere" HorizontalAlignment="Left" Height="35" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="126" Margin="315,10,0,0" />
<Button x:Name="Btnsearch" Content="Search" HorizontalAlignment="Left" Height="28" VerticalAlignment="Top" Width="112" Margin="316,57,0,0" Click="Btnsearch_Click"/>
VB
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
BingMap.Focus()
'Set map to Aerial Mode with labels
BingMap.Mode = New AerialMode(True)
End Sub
答案 0 :(得分:1)
你应该有更多或更少的想法,因为你设置了&#34;中心&#34;在Xaml。刚刚在C#中测试它然后转换为VB。让我知道这是否是您正在寻找的(Btnsearch_Click处理您的Btnsearch的Click事件):
Private Sub Btnsearch_Click(sender As Object, e As RoutedEventArgs)
Dim latitude As Double = Double.Parse(txtwhere.Text.Substring(0, txtwhere.Text.IndexOf(","C)))
Dim longitude As Double = Double.Parse(txtwhere.Text.Substring(txtwhere.Text.IndexOf(","C) + 1))
BingMap.Center = New Microsoft.Maps.MapControl.WPF.Location(latitude, longitude)
End Sub
当然,这假设文本框值以逗号分隔且有效。最好编写验证以避免错误。