- Hands-On Mobile Development with .NET Core
- Can Bilgin
- 311字
- 2021-06-24 13:55:37
Simple navigation
Within the Xamarin ecosystem, each platform has its own intrinsic navigation stack and applications are built around those stacks. Developers are responsible for maintaining these stacks in order to create the desired UX flow for users.
In order to navigate between pages, Xamarin.Forms exposes a Navigation service, which can be used together with the NavigationPage abstract page implementation. In other words, NavigationPage cannot be categorized as a page type to provide content for users, however, it is a crucial component to maintain the navigation stack, as well as the navigation bar, within Xamarin.Forms applications.
In our sample, we are navigating from ListItemView to ItemView. After this navigation, on iOS, you will notice that the title of the first page is inserted as back-button text in the navigation bar. Additionally, since the Title property is used for the ListItemView (that is, List), the text is additionally displayed in the navigation bar.
The creation of this navigation infrastructure is achieved by creating a NavigationPage and passing the desired page as the root of the navigation stack (looking at App.xaml.cs):
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new ListItemView());
}
The navigation from one page to the next is handled within the ItemTapped event handler for ListView:
private void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
{
var itemView = new ItemView();
itemView.BindingContext = e.Item;
Navigation.PushAsync(itemView);
}
Prior to Xamarin.Forms 3.2, the only way to customize what and how the navigation bar was displayed was using some form of native customization (for example, a custom renderer for NavigationPage). Nevertheless, you can now add custom elements to the navigation bar using the TitleView dependency property of a navigation page.
Using the ListItemView page for this illustration, we can add the following XAML section to our ContentPage:
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal" VerticalOptions="Center" Spacing="10">
<Image Source="Xamarin.png"/>
<Label
Text="Custom Title View"
FontSize="16"
TextColor="Black"
VerticalTextAlignment="Center" />
</StackLayout>
</NavigationPage.TitleView>
The resulting view will have the defined StackLayout instead of the List title that was previously displayed:

- 急性卒中機(jī)械取栓:現(xiàn)狀與經(jīng)驗(yàn)
- 腫瘤營(yíng)養(yǎng)診療規(guī)程
- 陳衛(wèi)川中回醫(yī)臨證實(shí)錄方
- 人體寄生蟲(chóng)學(xué)實(shí)驗(yàn)與學(xué)習(xí)指導(dǎo)(第2版)
- 口腔科常見(jiàn)及多發(fā)病就醫(yī)指南系列:口腔黏膜病就醫(yī)指南
- 角膜塑形鏡驗(yàn)配技術(shù)基礎(chǔ)篇
- 腦卒中預(yù)防與控制
- 臨床神經(jīng)遺傳病學(xué)
- 咳嗽百家百方
- 眼科手術(shù)操作與技巧(第2版)
- 血液病臨床診療精要
- 中醫(yī)臨床技能實(shí)訓(xùn)教程
- 骨骼肌損傷和重建的機(jī)制研究
- 會(huì)診聯(lián)絡(luò)精神醫(yī)學(xué)
- 醫(yī)療損害判例評(píng)析