Xamarin在PopModalAsync之后形成Android,看起来没有触发

Xamarin在PopModalAsync之后形成Android,看起来没有触发,xamarin,xamarin.android,xamarin.forms,Xamarin,Xamarin.android,Xamarin.forms,在仍然使用模式页面的情况下调用PopModalAsync后,Android不会触发是否有解决办法。以下是一个例子: using System; using Xamarin.Forms; namespace XamarinForms { public class OnAppearingBug : ContentPage { Label label; public OnAppearingBug () { lab

在仍然使用模式页面的情况下调用PopModalAsync后,Android不会触发是否有解决办法。以下是一个例子:

using System;
using Xamarin.Forms;

namespace XamarinForms
{
    public class OnAppearingBug : ContentPage
    {
        Label label;
        public OnAppearingBug ()
        {
            label = new Label {
                Text = "Page"
            };
            Button button = new Button {
                Text = "PushModal"
            };
            button.Clicked += (sender, e) => Navigation.PushModalAsync (new PopModalBug ());

            Content = new StackLayout {
                Children = { label, button }
            };
        }
        protected override void OnAppearing(){
            label.Text = "OnAppearing";
        }
    }
}

using System;
using Xamarin.Forms;

namespace XamarinForms
{
    public class PopModalBug : ContentPage
    {
        public PopModalBug ()
        {
            Button button = new Button {
                Text = "Pop Back"
            };
            //Bug: This will not trigger OnAppearing on Android
            button.Clicked += (sender, e) => Navigation.PopModalAsync();

            Content = new StackLayout {
                Children = { button }
            };
        }
    }
}

当你调用你的
Async
方法时,不要忘记等待,例如,按钮点击应该是这样的:

    button.Clicked += async (sender, e) => await Navigation.PopModalAsync();

    button.Clicked += async (sender, e) => await Navigation.PushModalAsync(new PopModalBug ());

我现在也有同样的问题。这非常令人沮丧,因为甚至没有一种方法可以使用自定义的呈现程序来实现,因为所有表单页面都被认为是android上的一项活动,因此它根本不会收到任何生命周期通知

我找到的唯一解决办法是使用。当内容页消失时,您只需从弹出窗口向内容页发送一条消息。这是一个额外的工作和意大利面,但目前这确实是唯一的办法

显然,一些附加功能即将推出,可能有助于解决此问题,但目前,没有多少其他功能可供使用。

另请参见和

但截至目前(Xamarin.Forms 1.2.2),唯一/最好的解决方案是CrisWebb提出的解决方案:

在主页上- MessagingCenter.Subscribe(这个“弹出的”,(发件人)=> { //要运行的代码 });

在模式页面上-
发送(这个“弹出”)

或者您可以使用pushModalAsync方法直接导航到页面。

这是keith\r指出的问题

作为MessagingCenter的替代方案,您可以使用Xamarin.Forms.Application事件,该事件在推送或弹出模式页面时触发

描述了应用程序事件


在Xamarin.Forms.Application MyApp类中,可以保留OnAppearingBug页面的句柄。在MyApp中,您可以根据需要在AppearingBug页面上收听模式页面推送/弹出和命令。

有一个简单的解决方法。例如,我的模式页面是一个日历,用户必须在弹出前选择一个日期

因此,在模式页面类中,只需创建一个事件(在我的例子中是OnDateSelected)
并从父页面创建引用。

我也面临同样的问题。NavigationPage文档的原因(有点类似于模式推送和弹出)
对于您推送或弹出的每个Xamarin.Forms.Page,Xamarin.Forms.NavigationPage的Android实现只是在单个活动中添加或删除页面内容。