【问题标题】:Xamarin Native to Forms transitionXamarin Native 到 Forms 的转换
【发布时间】:2020-01-22 11:03:43
【问题描述】:

我正在使用使用本机相机的 Xamarin 表单应用程序。我正在尝试从表单切换到本机,然后返回到基于https://github.com/supreettare/Forms2Native2Forms/blob/master/FormsBasics.Android/FormsActivity.cs的表单

在安卓中: SetPage(App.GetSecondPage());

在表格中:

public static Page GetSecondPage ()
    {
        var formsPage = new NavigationPage (new MyThirdPage ()); 

        return formsPage;
    }

我担心的是,当我调用这个函数时,它会给出 android.view.InflateException: Binary XML file line #1: Error inflating class

如果我执行 SetPage(new GetSecondPage()),我可以导航到另一个页面,但是 不能在该页面的任何位置使用 Navigation.PushAsync()

【问题讨论】:

标签: android xamarin xamarin.android navigation


【解决方案1】:

你试过用Page.CreateSupportFragment方法吗?

在您的活动中,您可以加载在表单中定义的页面,例如

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    Forms.Init(this, bundle);
    SetContentView(Resource.Layout.Main);          
    Android.Support.V4.App.Fragment mainPage = YourPage.CreateSupportFragment(this);
    SupportFragmentManager
        .BeginTransaction()
        .Replace(Resource.Id.fragment_frame_layout, mainPage)
        .Commit();

}

您可以参考Nativie Forms

【讨论】:

  • 这基本上是使用原生平台内部的表单,如果我没看错?
  • 实际上,这对我来说是很多工作。我也想实现 iOS,我也必须这样做。因此,我试图在保持相机原生的同时尽量减少原生功能。如果没有任何帮助,我将不得不这样做。
  • 你也可以在ios中使用类似的方法Page.CreateViewController。还有另一种方式,你可以使用消息中心在原生和表单之间进行通信,然后相互切换
  • 按照您的建议使用消息中心:App.cs 中的代码 MessagingCenter.Subscribe(this, "GoBack", (s) => { Device.BeginInvokeOnMainThread(() => MainPage.Navigation. PushAsync(new MainPage())); });另一个页面中发送的代码: Device.BeginInvokeOnMainThread( () => MessagingCenter.Send(this, "GoBack") 错误:Java.Lang.IllegalArgumentException: 'No view found for id 0x8e (unknown) for fragment FragmentContainer{ 669a3c6 #2 id=0x8e}'
猜你喜欢
  • 2018-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-03
  • 2023-03-07
  • 1970-01-01
相关资源
最近更新 更多