應用程式.xaml.cs
MainPage = new NavigationPage(new Home());
主頁.xaml.cs
public partial class Home : CarouselPage
{
public Home()
{
Children.Add(new CarPage1());
Children.Add(new CarPage2());
CurrentPage = new CarPage2();
}
}
CarPage2.xaml.cs
public partial class CarPage2 : ContentPage
{
public CarPage2()
{
InitializeComponent();
}
private void Btn_Clicked(object sender, EventArgs e)
{
//Do something
//I wanna change screen to CarPage1 without use Navigation.PushAsync(new CarPage1());
}
}
如何將當前螢屏更改為 CarPage1 不使用 Navigation.PushAsync ?
uj5u.com熱心網友回復:
我已經做了一個示例來測驗和設定 CurrentPage 屬性是否正常作業,您可以嘗試以下代碼:
public partial class CarPage2 : ContentPage
{
public CarPage2()
{
InitializeComponent();
}
private void Btn_Clicked(object sender, EventArgs e)
{
var home = this.Parent as CarouselPage;
home.CurrentPage = home.Children[0];
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/518618.html
標籤:xamarin