简体   繁体   English

如何从 xamarin.forms 调用特定于平台的页面

[英]how to call platform specific page from xamarin.forms

I am new to the xamarin app development, I have some questions :我是 xamarin 应用程序开发的新手,我有一些问题:

  1. Is it possible to call the platform specific page from the Xamarin.Form page?是否可以从 Xamarin.Form 页面调用特定于平台的页面?
  2. Can I do Page Navigation from view model?我可以从视图模型进行页面导航吗?

Let me explain clearly.让我解释清楚。

I have a Page XFView.xaml , XFView.xaml.cs and XFViewModel.cs in PCL (Xamarin.Forms) project from XFView.xaml.cs or XFViewModel.cs i want to call MAActivity.cs page which is present in Xamarin.Andriod project我有一个页面XFView.xamlXFView.xaml.csXFViewModel.cs在从PCL(Xamarin.Forms)项目XFView.xaml.csXFViewModel.cs我想打电话给MAActivity.cs页这是目前在Xamarin.Andriod项目

I tried a lot but got getting any idea.我尝试了很多,但得到了任何想法。

Whenever you would like to call something from native ( MAActivity.cs in your case), you have to use DependencyService.每当您想从本机(在您的情况下为MAActivity.cs )调用某些内容时,您都必须使用 DependencyService。

For example:例如:

  1. Setup dependency service设置依赖服务

    // PCL Project public interface INativePages { void StartMA(); } // MonoDroid Project [assembly: Dependency(typeof(NativePages))] public class NativePages : INativePages { public void StartMA() { var intent = new Intent(Forms.Context, typeof(MAActivity)); Forms.Context.StartActivity(intent); } }
  2. Invoke in PCL在 PCL 中调用

    // PCL Project DependencyService.Get<INativePages>().StartMA();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM