如何在Xamarin.Forms中切换页面? [英] How do you switch pages in Xamarin.Forms?

查看:179
本文介绍了如何在Xamarin.Forms中切换页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Xamarin表单中的页面之间切换?

How do you switch between pages in Xamarin Forms?

我的主页是ContentPage,我不想切换到选项卡式页面.

My main page is a ContentPage and I don't want to switch to something like a Tabbed Page.

通过找到应该触发新页面的控件的父级,直到找到ContentPage,然后将内容与控件换出新页面,我才能够进行伪操作.但这似乎很草率.

I've been able to pseudo-do it by finding parents of the controls that should trigger the new page until I find the ContentPage and then swap out the Content with controls for a new page. But this seems really sloppy.

推荐答案

Xamarin.Forms支持多个内置的导航主机:

Xamarin.Forms supports multiple navigation hosts built-in:

  • NavigationPage,下一页将滑入其中,
  • TabbedPage,您不喜欢的人
  • CarouselPage,允许左右切换到下一页/上一页.
  • NavigationPage, where the next page slide in,
  • TabbedPage, the one you don't like
  • CarouselPage, that allows for switching left and right to next/prev pages.

此外,所有页面还支持PushModalAsync(),只需将新页面推入现有页面的顶部即可.

On top of this, all pages also supports PushModalAsync() which just push a new page on top of the existing one.

最后,如果要确保用户无法返回上一页(使用手势或后退硬件按钮),则可以保持显示相同的Page并替换其.

At the very end, if you want to make sure the user can't get back to the previous page (using a gesture or the back hardware button), you can keep the same Page displayed and replace its Content.

建议的替换根页面的选项也可以使用,但是对于每个平台,您都必须以不同的方式进行处理.

The suggested options of replacing the root page works as well, but you'll have to handle that differently for each platform.

这篇关于如何在Xamarin.Forms中切换页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆