Xamarin.Forms提供了许多不同的页面导航体验,具体取决于所使用的页面类型对于ContentPage实例,有两种导航体验:
Hierarchical Navigation Modal NavigationCarouselPage,MasterDetailPage和TabbedPage类提供了替代的导航体验更多资料:https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/
NavigationPage类提供了一种分层导航体验,用户可以根据需要在页面中进行导航,向前和向后导航该类实现导航作为Page对象的后进先出(LIFO)堆栈在分层导航中,NavigationPage类用于浏览一堆ContentPage对象要从一个页面移动到另一个页面,应用程序会将新页面推到导航堆栈上,在那里它将成为活动页面要返回到上一页面,应用程序将从导航堆栈中弹出当前页面,并且新的最顶端页面将成为活动页面
添加到导航堆栈的第一个页面被称为应用程序的根页面在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 } };https://github.com/zLulus/NotePractice/tree/dev3/Xamarin.Forms/XamarinDemo/XamarinDemo/XamarinDemo从MainPage->StackLayoutExample
使用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 } };https://github.com/zLulus/NotePractice/tree/dev3/Xamarin.Forms/XamarinDemo/XamarinDemo/XamarinDemo从MainPage->ListViewInStackLayout
转载于:https://www.cnblogs.com/Lulus/p/8179029.html