[英]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.