how to call platform specific page from xamarin.forms

后端 未结 1 1736
梦谈多话
梦谈多话 2021-02-04 13:38

I am new to the xamarin app development, I have some questions :

  1. Is it possible to call the platform specific page from the Xamarin.Form page?
  2. Can I
相关标签:
1条回答
  • 2021-02-04 14:03

    Whenever you would like to call something from native (MAActivity.cs in your case), you have to use 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 Project
      DependencyService.Get<INativePages>().StartMA();
      
    0 讨论(0)
提交回复
热议问题