xamarin跳转html,Xamarin 跳转页面

准备三个 ContentPage 对象,暂时无需xaml:

MainPage.cs、ModelessPage.cs、ModalPage.cs。

MainPage.cs:

using System;

using Xamarin.Forms;

namespace one

{

public class MainPage : ContentPage

{

public MainPage()

{

Title = "Main Page";

Button gotoModelessButton = new Button {

Text = "Go to modeless Page",

HorizontalOptions = LayoutOptions.Center,

VerticalOptions = LayoutOptions.CenterAndExpand

};

gotoModelessButton.Clicked += async (sender, e) => {

await Navigation.PushAsync(new ModelessPage());

};

Button gotoModalButton = new Button {

Text = "Go to Modal Page",

HorizontalOptions = LayoutOptions.Center,

VerticalOptions = LayoutOptions.CenterAndExpand

};

gotoModalButton.Clicked += async (sender, e) => {

await Navigation.PushModalAsync(new ModalPage());

};

Content = new StackLayout

{

Children = {

gotoModelessButton,

gotoModalButton

}

};

}

}

}

ModelessPage.cs:

using System;

using Xamarin.Forms;

namespace one

{

public class ModelessPage : ContentPage

{

public ModelessPage()

{

Title = "Modeless Page";

Button goBackButton = new Button {

Text = "Back to Main",

HorizontalOptions = LayoutOptions.Center,

VerticalOptions = LayoutOptions.Center

};

goBackButton.Clicked += async (sender, e) => {

await Navigation.PopAsync();

};

Content = goBackButton;

}

}

}

ModalPage.cs:

using System;

using Xamarin.Forms;

namespace one

{

public class ModalPage : ContentPage

{

public ModalPage()

{

Title = "Modal Page";

Button goBackButton = new Button

{

Text = "Back to Main",

HorizontalOptions = LayoutOptions.Center,

VerticalOptions = LayoutOptions.Center

};

goBackButton.Clicked += async (sender, e) => {

await Navigation.PopModalAsync();

};

Content = goBackButton;

}

}

}

加载内容:

using Xamarin.Forms;

namespace one

{

public partial class App : Application

{

public App()

{

MainPage = new NavigationPage(new MainPage());

}

protected override void OnStart()

{

// Handle when your app starts

}

protected override void OnSleep()

{

// Handle when your app sleeps

}

protected override void OnResume()

{

// Handle when your app resumes

}

}

}

运行~~:

7a291666d5213a1fd469e8db68db14e2.png

点击"Go to modeless Page":

b5183fc2560c91433f1e888844363c5b.png

点击 "Back to Main" 即可返回到首页,与 顶部左边的 Back 按钮同等功能。

点击"Go to Modal Page":

05ea292ff686f59d0dc8ae8feb4cce56.png

点击 "Back to Main" 即可返回到首页。

总结一下:

Navigation.PushAsync() 类似 iOS 中 UINavigationController 的 pushViewController;

Navigation.PushModalAsync() 类似 iOS 中 presentViewController;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值