6

在仍然使用模态页面的同时调用 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 }
            };
        }
    }
}
4

6 回答 6

6

另请参阅http://forums.xamarin.com/discussion/21417/navigationpage-push-pop-event-sequence-different-across-platformshttp://forums.xamarin.com/discussion/18781/ios-and- android-different-behaviors-for-onappearing

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

在您的主页上 - MessagingCenter.Subscribe(this, "popped", (sender) => { // code to run });

在您的模式页面上 - MessagingCenter.Send(this, "popped");

于 2014-09-03T14:19:35.617 回答
2

如 keith_r 所示,这是一个问题。

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

此处描述的应用程序事件。

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

于 2015-07-09T10:16:13.480 回答
0

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

于 2014-09-16T08:56:45.877 回答
0

我现在实际上有同样的问题。它非常令人沮丧,因为甚至没有办法使用自定义渲染器滚动您自己的,因为所有表单页面都被认为是 android 上的一个活动,因此它根本不会收到任何生命周期通知。

我发现的唯一解决方案是使用MessagingCenter。您需要做的就是在弹出窗口消失时向您的内容页面发送一条消息。它有点额外的工作和意大利面,但目前它确实是唯一的方法。

显然,即将推出的一些附加功能可能有助于解决这个问题,但目前,没有什么可做的。

于 2014-08-18T00:30:42.497 回答
0

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

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

    button.Clicked += async (sender, e) => await Navigation.PushModalAsync(new PopModalBug ());
于 2014-07-29T15:30:26.090 回答
0

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

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

于 2016-02-17T19:14:27.880 回答