gpt4 book ai didi

Xamarin Forms Android OnAppearing 在 PopModalAsync 后不触发

转载 作者:行者123 更新时间:2023-12-02 18:31:02 33 4
gpt4 key购买 nike

是否有解决方法可以解决在仍然使用模态页面时调用 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 }
};
}
}
}

最佳答案

另请参阅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(这个, "弹出", (发件人) => { //要运行的代码 });

在您的模态页面上 - MessagingCenter.Send(this, "弹出");

关于Xamarin Forms Android OnAppearing 在 PopModalAsync 后不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24998149/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com