我想从ViewModel中给出经度和纬度。
现在我使用的是:-
private void button1_Click(object sender, RoutedEventArgs e)
{
Pushpin p = new Pushpin();
p.Background = new SolidColorBrush(Colors.Yellow);
p.Foreground = new SolidColorBrush(Colors.Black);
p.Location = new GeoCoordinate(double.Parse(longitude.Text), double.Parse(latitude.Text));
p.Content = "I'm here";
map1.Children.Add(p);
map1.SetView(new GeoCoordinate(double.Parse(longitude.Text), double.Parse(latitude.Text), 200), 9);
}
我的Xaml是:-
<Grid x:Name="MapPageUIContainer" Grid.Row="1" Margin="2,0,2,0">
<my:Map CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" CredentialsProvider="" Mode="AerialWithLabels" Height="543" HorizontalAlignment="Left" Name="map1" VerticalAlignment="Top" Width="480" Margin="2,100,0,0" />
<Border BorderBrush="Silver" BorderThickness="1" Height="100" HorizontalAlignment="Left" Margin="0,0,0,0" Name="border1" VerticalAlignment="Top" Width="476" Background="#FFA3A371">
<TextBlock Text="Map Example" HorizontalAlignment="Center" FontSize="32" FontWeight="Bold" VerticalAlignment="Center" />
</Border>
<TextBox Height="72" HorizontalAlignment="Left" Margin="6,627,0,0" Name="longitude" Text="" VerticalAlignment="Top" Width="200" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="260,627,0,0" Name="latitude" Text="" VerticalAlignment="Top" Width="200" />
<Button Content="Set" HorizontalAlignment="Left" Margin="190,690,0,0" Name="button1" VerticalAlignment="Top" Click="button1_Click" />
</Grid>
这里我想给出图钉,经度,视图模型的纬度。请告诉我如何做到这一点?
提前感谢。。
我试过这样做。。
public class MapPageViewModel : ReactiveObject
{
public static string _longitude;
public string longitude
{
get { return _longitude; }
set { this.RaiseAndSetIfChanged(x => x.longitude, value); }
}
public static string _latitude;
public string latitude
{
get { return _latitude; }
set { this.RaiseAndSetIfChanged(x => x.latitude, value); }
}
public ReactiveAsyncCommand setButton { get; set; }
public MapPageViewModel()
{
setButton = new ReactiveAsyncCommand();
setButton.Subscribe(x => {
Pushpin p = new Pushpin();
p.Background = new SolidColorBrush(Colors.Yellow);
p.Foreground = new SolidColorBrush(Colors.Black);
p.Location = new GeoCoordinate(double.Parse(longitude), double.Parse(latitude));
p.Content = "I'm here";
});
}
}
但我不知道如何设置map1.Children.Add()和map1.SetView,以及如何在Map中绑定这些值?
你好,克莱门斯。我已经试过你的指示了。但它显示出错误。
我也尝试过:-
public MapPageViewModel()
{
PushpinItems = new ObservableCollection<PushpinItem>();
PushpinItem pp = new PushpinItem();
setButton = new ReactiveAsyncCommand();
setButton.Subscribe(x => {
pp.Location = new GeoCoordinate(double.Parse(longitude), double.Parse(latitude));
pp.Text = "I'm here";
PushpinItems.Add(pp);
});
}
但这里发生了运行时错误。请告诉我我做错了什么。