c# - 如何在虚拟机中更改 Map 的 MapType?
问题描述
我有一张想要从 VM 添加的地图。当您单击按钮时,我尝试添加命令 MapType 将被更改。但它不起作用。我知道如何在代码隐藏中制作它。但我需要 VM
ContentView
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="All"
Content="{Binding Map}" />
虚拟机
public Map Map { get; set; }
public Command StandartMapCommand { get; set; }
public Command SatelliteMapCommand { get; set; }
public Command HybridMapCommand { get; set; }
public MasterPageVM()
{
Map = new Map();
StandartMapCommand = new Command(StandardSelected);
SatelliteMapCommand = new Command(SatelliteSelected);
HybridMapCommand = new Command(HybridSelected);
}
public void StandardSelected()
{
Map.MapType = Xamarin.Forms.Maps.MapType.Street;
}
public void HybridSelected()
{
Map.MapType = Xamarin.Forms.Maps.MapType.Hybrid;
}
public void SatelliteSelected()
{
Map.MapType = Xamarin.Forms.Maps.MapType.Satellite;
}
当我点击按钮地图不会改变 MapType.pls 帮助
解决方案
我有一张想要从 VM 添加的地图。当您单击按钮时,我尝试添加命令 MapType 将被更改。但它不起作用。我知道如何在代码隐藏中制作它。但我需要 VM
如果你想改变 viewmodel 中的 Map.Maptype,你可以看看下面的代码。
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentView Grid.ColumnSpan="3" Content="{Binding Map}" />
<Button
x:Name="btn1"
Grid.Row="1"
Command="{Binding StandartMapCommand}"
Text="Street" />
<Button
x:Name="btn2"
Grid.Row="1"
Grid.Column="1"
Command="{Binding SatelliteMapCommand}"
Text="Satellite" />
<Button
x:Name="btn3"
Grid.Row="1"
Grid.Column="2"
Command="{Binding HybridMapCommand}"
Text="Hybrid" />
</Grid>
</ContentPage.Content>
public partial class Page1 : ContentPage
{
public Page1 ()
{
InitializeComponent ();
this.BindingContext = new MapViewModel();
}
}
public class MapViewModel
{
private Map _map;
public Map Map
{
get { return _map; }
set
{
_map = value;
}
}
public Command StandartMapCommand { get; set; }
public Command SatelliteMapCommand { get; set; }
public Command HybridMapCommand { get; set; }
public MapViewModel()
{
Map = new Map();
Position position = new Position(36.9628066, -122.0194722);
MapSpan mapSpan = new MapSpan(position, 0.01, 0.01);
Map.MoveToRegion(mapSpan);
Map.Pins.Add(new Pin
{
Label = "Xamarin",
Position = position
});
StandartMapCommand = new Command(streetcommand);
SatelliteMapCommand = new Command(Satellitecommand);
HybridMapCommand = new Command(Hybridcommand);
}
private void streetcommand()
{
Map.MapType = MapType.Street;
}
private void Satellitecommand()
{
Map.MapType = MapType.Satellite;
}
private void Hybridcommand()
{
Map.MapType = MapType.Hybrid;
}
}
推荐阅读
- java - 与常规查询相比,Hibernate 的命名查询性能是否更好?
- php - Wordpress 缓存并重定向到主页以外任何页面的旧 URL
- sql - 使用函数调用从选择中插入到表的 Oracle 中的性能
- java - Springboot java @CrossOrigin 不起作用,因为它应该起作用,当这个注释存在时为什么我必须做额外的配置?
- kubernetes - k8s中pod的执行顺序是如何决定的?
- odoo - 在配置文件odoo中设置和获取默认值
- php - Google AMP:amp-list 与 php 循环 - SEO / Pagespeed
- java - “导入组织无法解析”在带有 selenium Standalone server 3.9.1 的 Eclipse Photon 中导入错误
- c# - ASP.NET WebAPI 和 Razor 页面位于同一 Web 位置
- javascript - React - 如果事件是从此组件当前呈现的元素触发的,则不要调用方法