有没有办法从Android调用PCL方法?

时间:2017-08-23 09:54:21

标签: xamarin xamarin.android xamarin.forms

我想在信息窗口点击时从一个页面导航到另一个页面,我有一个自定义地图渲染器。任何人都可以建议我如何从自定义渲染器导航到其他视图。在此先感谢:)

1 个答案:

答案 0 :(得分:2)

你真的想让Android项目和PCL分离,所以我会使用MessagingService从Android项目发送一条消息,然后由PCL接收。

<强> YourCustomRenderer:

MessagingService.Current.SendMessage("NavigateMessage", new NavigationParamsModel
{
    TargetPage = "DetailsPage",
    Id = 12,
    SomethingElse = "blahblah"
});

<强> PCL:

MessagingService.Current.Subscribe<NavigationParamsModel>("NavigateMessage", async (arg1, arg2) => 
{
    // Just an example of how this would be done using Prism.Navigation. 
    // Pure Xamarin.Forms navigation is obviously different.
    _navigationService.NavigateAsync(arg2.TargetPage);
});