因爲我是Xamarin新手,我真的不知道如何在頁面之間切換。所以我提到互聯網並找到了一些解決方案。但有一些錯誤。任何人都可以幫助解決這個問題?這是我在app.cs文件中的代碼。我對代碼進行評論,我不確定。當我點擊btn1時,觸發了一個名爲「pushAsync在ios上不支持全局」的錯誤。使用Xamarin.Forms我需要從一個頁面導航到另一個頁面上xamarin.Forms.app
using System;
;
命名空間礦山 { 公共類應用:應用 { 公共應用程序(){
// The root page of your application
Button btn1 = new Button();
Button btn2 = new Button();
Button btn3 = new Button();
btn1.Text= "Farmer";
btn2.Text= "Advisor";
btn3.Text= "Supplier";
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Rice Growing Advisor!"
//App.Navigation.PushAsync(new MyCustomContentPage());
//App.Navigation.PushAsync (new MainPage());
}, btn1,btn2,btn3
}
}
};
//var np = new NavigationPage(new MainPage());
//MainPage=np;
//MainPage = new NavigationPage (MainPage);
//var rootPage = new NavigationPage(MainPage);
btn1.Clicked += async (sender, e) => {
//MainPage= new NavigationPage(new MainPage());
//MainPage = np;
await MainPage.Navigation.PushAsync(new NavigationPage());
MainPage.Navigation.RemovePage(MainPage);
};
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
您需要首先將您的主頁設置爲導航頁面,然後在其上按下頁面。 –
當問題 聲明僅僅是「它不起作用」時,很難提供解決方案。請編輯您的 問題,以更全面地描述您的 預期會發生什麼,以及與實際的 結果有何不同。請參閱[問]提示什麼使得一個好的 解釋。 –
@TobySpeight他在代碼中將錯誤寫爲註釋。 –