简体   繁体   English

如何在Xamarin.Forms中更改页面?

[英]How can I change the Page in Xamarin.Forms?

I am on FirstPage and want to change to SecondPage by calling 我在FirstPage上,想通过调用更改为SecondPage

await Navigation.PushAsync(new SecondPage());

But I always get an Exception. 但是我总是会得到一个例外。 How do I navigate? 我该如何导航?

PushAsync is for use in a NavigationPage which handles Navigation for you. PushAsync可在为您处理导航的NavigationPage中使用。 For this create your MainPage in your App class like this: 为此,在您的App类中创建您的MainPage,如下所示:

MainPage = new NavigationPage(new FirstPage());

Then you can use PushAsync. 然后,您可以使用PushAsync。

If you don't want to use a NavigationPage for certain reasons, you should use 如果出于某些原因不想使用NavigationPage,则应使用

await Navigation.PushModalAsync(new SecondPage());

With this you have something like a two-dimensional navigation stack. 有了这个,您就可以像二维导航堆栈一样。

You need to set your First Page as your main page. 您需要将首页设置为主页。

MainPage=new NavigationPage(new FirstPage());

And from the FirstPage you can go to the second page using a click event 从第一页,您可以使用点击事件转到第二页

btnTest.Clicked += async (sender, e) =>
{
    await Navigation.PushAsync(new SecondPage());
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改原始选项卡页面栏的样式(android with xamarin.forms)? - How can I change style of the original tabbed page bar (android with xamarin.forms)? 如何从 Android MainActivity.cs 文件中更改 Xamarin.forms 中页面 Label 的文本? - How can I change the text of a page's Label in Xamarin.forms from the Android MainActivity.cs file? 我可以在 Xamarin.Forms 中以编程方式更改 style.xml 吗? - Can I programmatically change styles.xml in Xamarin.Forms? 如何使用 c# 在 xamarin.forms 登录成功后更改内容 - How can i change content after login success in xamarin.forms using c# 如何根据 xamarin.forms 中的条件更改条目的线条颜色 - How can i change the line color of an entry based on a condition in xamarin.forms 如何在Xamarin.Forms中为ToolbarItem创建自定义渲染器? - How can I make a custom renderer for ToolbarItem in Xamarin.Forms? 如何在Xamarin.Forms中为轮播实现活动指示器? - How can I implement an Activity Indicator for a Carousel in Xamarin.Forms? 如何在Xamarin.Forms的TabbedPage的选项卡中放置按钮? - How can I place a button in the the tabs of a TabbedPage in Xamarin.Forms? 如何使用 XAML 在 Xamarin.Forms 的 ListView 中选择一个项目 - How can I select an item in a ListView in Xamarin.Forms with XAML 如何在 Xamarin.Forms 中显示 Label 的结尾? - How can I show end of Label in Xamarin.Forms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM