Cannot open a Xamarin.Forms “Page” from Xamarin.Android

↘锁芯ラ 提交于 2019-12-25 00:13:26

问题


Context: Our team is trying to use Xamarin.Forms (XF) Embedding to slowly convert our project from using Xamarin.Native to XF, for easier maintenance & implementation of features in the future.

The Problem: As you can see in the function parameters on the lines referenced by the links, Xamarin allows you to convert any type of XF Page to a native ViewController in iOS, but it only allows converting a XF ContentPage to a native Fragment in Android.

Importance: This difference plays a major role, because through Xamarin.Native Android, you can't implement a XF NavigationPage. What does that mean? From within Xamarin.Native Android, you can't convert your app to use XF, so you can't call functions like PushAsync or PopAsync.

Added Explanation: You can open NavigationPages on iOS, as you can see in this sample here which allows using functions like PushAsync or PopAsync, by simply doing:

UIViewController user2 = new NavigationPage(new TestPage()).CreateViewController();

So for Android as seen here, currently we can only do this

Android.Support.V4.App.Fragment fragment = new TestPage().CreateSupportFragment(this);

and I was wondering is there a way to do something like this?

Android.Support.V4.App.Fragment fragment = new NavigationPage(new TestPage()).CreateSupportFragment(this);

Question: Has anyone opened a Xamarin.Forms NavigationPage from Xamarin.Android native before? Does anyone know of a workaround that will allow us to use the PushAsync and PopAsync functions?

PS: Here's the Github playground which was a Spike

来源:https://stackoverflow.com/questions/58508566/cannot-open-a-xamarin-forms-page-from-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!