xamarin跳转html,Xamarin 页面跳转

简介

Xamarin.Forms提供了许多不同的页面导航体验,具体取决于所使用的页面类型

对于ContentPage实例,有两种导航体验:

Hierarchical Navigation

Modal Navigation

Hierarchical Navigation

NavigationPage类提供了一种分层导航体验,用户可以根据需要在页面中进行导航,向前和向后导航

该类实现导航作为Page对象的后进先出(LIFO)堆栈

在分层导航中,NavigationPage类用于浏览一堆ContentPage对象

要从一个页面移动到另一个页面,应用程序会将新页面推到导航堆栈上,在那里它将成为活动页面

要返回到上一页面,应用程序将从导航堆栈中弹出当前页面,并且新的最顶端页面将成为活动页面

根页面设置为NavigationPage

添加到导航堆栈的第一个页面被称为应用程序的根页面

在App中修改起始页的设置

MainPage = new NavigationPage(new MainPage());

跳转页面

使用Navigation.PushAsync()方法

Button StackLayoutDemo1Button = new Button();

StackLayoutDemo1Button.Clicked += ((sender,e)=>

{

Navigation.PushAsync(new StackLayoutExample());

});

StackLayoutDemo1Button.Text = "StackLayout+Label"; //内容 Content = new StackLayout { //间距 Spacing = 10, Children = { StackLayoutDemo1Button } };

返回上一页

使用Navigation.PopAsync()方法

var backButton = new Button();

backButton.Text = "返回";

backButton.Clicked += ((sender,e) => { Navigation.PopAsync(); }); //内容 Content = new StackLayout { Spacing = 10, Children = { backButton } };

示例代码

Modal Navigation

A NavigationPage instance is not required for performing modal page navigation.

执行Modal Navigation不需要NavigationPage的实例

跳转页面

使用Navigation.PushModalAsync()方法

StackLayoutDemo1Button.Text = "StackLayout+Label";

Button StackLayoutDemo1Button2 = new Button();

StackLayoutDemo1Button2.Clicked += ((sender,e)=> {

Navigation.PushModalAsync(new ListViewInStackLayout()); }); StackLayoutDemo1Button2.Text = "StackLayout+ListView"; //内容 Content = new StackLayout { //间距 Spacing = 10, Children = { StackLayoutDemo1Button2 } };

返回上一页

使用Navigation.PopModalAsync()方法

var backButton = new Button();

backButton.Text = "返回";

backButton.Clicked += ((sender, e) => { Navigation.PopModalAsync(); }); Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, Children = { backButton } };

示例代码

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值