Xamarin.Forms获得特定设备的code回窗体数据 [英] Xamarin.Forms get data from device specific code back to the Forms

查看:617
本文介绍了Xamarin.Forms获得特定设备的code回窗体数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我都试过了,没有运气,从Xamarin.Forms code中获取当前位置。我试着在移动服务从自己的样品code Xamarin.Forms (这里找到的 http://github.com/aritchie/acr-xamarin-forms ),但它是非常复杂的,有没有意见,所以不容易。
 我能得到它的设备特定code(在这种情况下Android的),但只有一个活动,我不知道如何得到它返回到窗体。由于Xamarin.Forms那么新的没有太多的文件,只有什么是可能的引用。

I have tried, without luck, to get the current location from within the Xamarin.Forms code. I tried the Mobile Services for Xamarin.Forms from their sample code (found here http://github.com/aritchie/acr-xamarin-forms) but it is very complex and there are no comments, so it is not easy to follow. I can get it in the device specific code (in this instance Android), but only in an Activity, and I have no idea how to get it back to the Forms. As Xamarin.Forms are so new there is not much documentation, only references to what is possible.

我已经看过这样的:<一href=\"http://stackoverflow.com/questions/24251020/write-device-platform-specific-$c$c-in-xamarin-forms\">Write在Xamarin.Forms设备平台特定的code 的,但我不认为这是我所追求的,因为我需要能够调用它,不让它在启动时(我可能是完全错误的虽然这里,我只用Xamarin一点点了一个多星期了,而2天Xamarin.Forms)

I have looked at this: Write device platform specific code in Xamarin.Forms but I don't think it is what I am after as I need to be able to call it, not get it on start-up (I may be completely wrong here though, I have only been using Xamarin for a little over a week, and Xamarin.Forms for 2 days)

我撕裂我的头发,所以任何建议将大大AP preciated。

I am tearing my hair out, so any suggestions will be greatly appreciated.

推荐答案

看看 Xamarin.Forms.Labs.Resolver 类,从的NuGet添加实验室包。

Take a look at Xamarin.Forms.Labs.Resolver class, add the Labs package from NuGet.

要使用它使一个接口在您的表格项目IMyService,在iOS版/ Android项目做一个实现IMyService一类。

To use it make an interface in your Forms project IMyService, in the iOS/Android project make a class that implements IMyService.

在您的AppDelegate注册解析器服务

In your AppDelegate register the service with Resolver

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
  var resolverContainer = new SimpleContainer ();
  resolverContainer.Register<IMyService>(t=>new MyServiceImplementorClass()); 
  Resolver.SetResolver (resolverContainer.GetResolver ());
}

然后,只要您需要在表单中使用您的服务调用Resolver.Resolve:

Then wherever you need to use your service in Forms call Resolver.Resolve:

IMyService fileAccess = Resolver.Resolve<IMyService> (); 

这篇关于Xamarin.Forms获得特定设备的code回窗体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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