从ViewModel绑定到Xamarin.Forms.Maps.Map [英] Bind to Xamarin.Forms.Maps.Map from ViewModel

查看:189
本文介绍了从ViewModel绑定到Xamarin.Forms.Maps.Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XAMarin.Forms应用程序,使用显示地图的页面。
XAML是:

I'm working on a Xamarin.Forms app using a page that displays a map. The XAML is:

<maps:Map x:Name="Map">
    ...
</maps:Map>

我知道可以从页面的代码隐藏访问地图,如下所示:

I know that the map can be accessed from the page's code-behind like this:

var position = new Position(37.79762, -122.40181);
Map.MoveToRegion(new MapSpan(position, 0.01, 0.01));
Map.Pins.Add(new Pin
{
    Label = "Xamarin",
    Position = position
});

但是因为这段代码会破坏应用程序的MVVM架构,所以我宁愿访问 Map 我的ViewModel对象,而不是直接从View / page - 直接使用它,就像上面的代码一样,或者通过数据绑定到它的属性。

But because this code would break the app's MVVM architecture, I'd rather like to access the Map object from my ViewModel, not directly from the View/page - either using it directly like in the above code or by databinding to its properties.

有没有人知道如何做到这一点?

Does anybody know a way how this can be done?

推荐答案

我不认为 Pins Map 上的一个可绑定属性,您可能需要在Xamarin的 Uservoice 或这里的fourm: http://forums.xamarin.com/discussion/31273/

I don't think Pins is a bindable property on Map, you may want to file feature request at Xamarin's Uservoice or the fourm here: http://forums.xamarin.com/discussion/31273/

这篇关于从ViewModel绑定到Xamarin.Forms.Maps.Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆