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

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

问题描述

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

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,然后将 Content 与新页面的控件交换出来,我已经能够进行伪操作.但这看起来真的很草率.

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并替换其Content.

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天全站免登陆