我已经尝试过了,但是没有用
private async void SignUpLink_OnTapped(object sender, EventArgs e)
{
await Navigation.PopModalAsync();
await Navigation.PushModalAsync(new SignUp());
}
答案 0 :(得分:1)
模式页面对象一旦弹出便被销毁,因此您可以使用此替代方法,该方法可行,因为当您使用PopModalAsync()时,它将在调用页面(您从中显示该页面)中触发OnAppearing()事件。模态页面)。因此,从模式页面返回后(在您看来只是呈现另一个模式页面)之后要做一些事情,您可以:
public class NonModalCallingPage
{
private bool ReturnedFromModalPage = false;
private async void YourButtonClickedToOpenFirstModal (object sender, EventArgs e)
{
ReturnedFromModalPage = false;
await Navigation.PushModalAsync(new NavigationPage(new FirstModalPage()));
ReturnedFromModalPage = true;
}
protected override async void OnAppearing()
{
base.OnAppearing();
if (ReturnedFromModalPage)
{
ReturnedFromModalPage = false;
await Navigation.PushModalAsync(new SignUp());
}
}
}
答案 1 :(得分:0)
有可能。您可以使用 delegate 来实现它。我将显示 MainPage / SecondPage / ThirdPage 显示它。
在 PageA 中定义一个委托及其调用方法:
public partial class MainPage : ContentPage
{
//declare a delegate in MainPage
public delegate void MyDelegate(bool val);
public MainPage()
{
InitializeComponent();
}
async private void Button_Clicked(object sender, EventArgs e)
{
// navigate to second page with delegate
await Navigation.PushModalAsync(new SecondPage(DeleagteVoid));
}
// invoked by poping back
private async void DeleagteVoid (bool value)
{
//When delegate method invoked , by value to determine whether to push to next page
Console.WriteLine("---" + value);
if (value)
{
// if true , push to third page
await Navigation.PushModalAsync(new ThirdPage());
}
}
}
弹出上一页时, 第二页调用delegate
中的MainPage
方法:
public partial class SecondPage : ContentPage
{
// declare delegate also in second page
MyDelegate myDelegate;
public SecondPage(MyDelegate deleagteVoid)
{
InitializeComponent();
// assign delegate
this.myDelegate = deleagteVoid;
}
private async void Button_Clicked(object sender, EventArgs e)
{
// pop to previous page
await Navigation.PopModalAsync();
//invoke delegate method in MainPage
myDelegate(true);
}
}
第三页做其他您想做的事情。
答案 2 :(得分:0)
您可以使用App.Current.MainPage进行导航。
private async void Button_Clicked(object sender, EventArgs e)
{
var mp = App.Current.MainPage;
await mp.Navigation.PopModalAsync(); //PopModalAsync(false) if you want to skip animation
await mp.Navigation.PushModalAsync(new NewPage());
}