c#-Xamarin,使用Xlabs示例中的Geolocation

c#-Xamarin,使用Xlabs示例中的Geolocation,第1张

概述使用Xamarin共享项目.我试图在我的共享项目中包含Xlabs示例中的Geolocation功能,但是在调用dependencyService时遇到了问题.我有一个内容页面,并且在其中有一个具有如下命令的按钮:Command=newCommand(async()=>awaitGetPosition(),()=>Geolocator!=null)该命令导致:priva

使用Xamarin共享项目.

我试图在我的共享项目中包含Xlabs示例中的Geolocation功能,但是在调用dependencyService时遇到了问题.

我有一个内容页面,并且在其中有一个具有如下命令的按钮:Command = new Command(async()=> await Getposition(),()=> Geolocator!= null)

该命令导致:

private IGeolocator Geolocator    {        get        {            if (_geolocator == null)            {                _geolocator = DependencyService.Get<IGeolocator>();                _geolocator.positionError += OnListeningError;                _geolocator.positionChanged += OnpositionChanged;            }            return _geolocator;        }    }

以及何时应调用_geolocator = DependencyService.Get< IGeolocator>();没有任何反应,_geolocator保持为空.

我有来自Xlabs的所有引用,并且IGeolocator接口在我的项目中,所以为什么不调用DependencyService?

解决方法:

XLabs.Platform服务不再(自更新至2.0)不再自动向Xamarin.Forms.DependencyService注册.这是由于删除了XLabs.Platform上的Xamarin.Forms依赖关系.您可以手动注册Geolocator(从每个平台特定的项目中注册):

 DependencyService.Register<Geolocator> ();

更好的选择是使用XLabs.IoC提供的IoC容器抽象(作为依赖项自动包含):https://github.com/XLabs/Xamarin-Forms-Labs/wiki/IOC

有关XLabs.IoC的更多信息:http://www.codenutz.com/autofac-ninject-tinyioc-unity-with-xamarin-forms-labs-xlabs/

总结

以上是内存溢出为你收集整理的c#-Xamarin,使用Xlabs示例中的Geolocation全部内容,希望文章能够帮你解决c#-Xamarin,使用Xlabs示例中的Geolocation所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095609.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存