[英]How can I set different Title Views for different pages in TabbedPage layout in Xamarin.Forms?
I have a main Navigation Page that is a Tabbed Page, linking different views. 我有一个主导航页,它是一个选项卡式页面,链接着不同的视图。
I've set the in the main Tabbed Page and it works, but I would like to set it different for each page. 我已经在主选项卡式页面中进行了设置,并且可以使用,但是我想为每个页面设置不同的内容。
This is the Tabbed Page: 这是选项卡式页面:
<TabbedPage
NavigationPage.HasBackButton="False"
BackgroundColor="Black"
xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestProiectLicenta.Views.UserPageForm" xmlns:local="clr-namespace:TestProiectLicenta.Views"
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
xmlns:refresh="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh">
<TabbedPage.Children>
<local:CarsListPage Title="Cars" Icon="new_car_icon"/>
<local:NewCarsListPage Title="New Cars" Icon="new_car_icon"/>
<local:ChooseMethodFormPage Title="Add Car" Icon="new_add_icon" />
<local:UserViewPage Title="New Page Test" Icon="new_user_icon" />
<ContentPage Title="Settings" Icon="new_settings_icon.png">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Horizontal">
<Image Source="face_id" />
<Label Text="FaceID Login?" />
</StackLayout>
<Switch IsToggled="false" Toggled="Handle_Toggled" x:Name="Fid" />
</StackLayout>
<Button Text="Sign Out" Clicked="SignOutButton" />
</StackLayout>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
The views are Content Pages. 这些视图是内容页面。
I would like to have a Title View for the first page with some controls, like search, delete etc. (it's a list of cars) and the user's picture, and the others with the title and maybe other controls. 我想为首页提供一个标题视图,其中包含一些控件,例如搜索,删除等(这是汽车列表)和用户图片,而其他控件则具有标题和其他控件。
Usually what I do is I set the Title
property in every ContentPage
and it reflects on to the page when I flip through tabs 通常我要做的是在每个
ContentPage
设置Title
属性,当我翻动标签时它会反映到页面上
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.BackButtonTitle=""
Title="My Demo Title">...
In your TabbedPage, you can add the NavigationPage's
TitleView
something like below 在您的TabbedPage中,您可以添加
NavigationPage's
TitleView
,如下所示
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.BackButtonTitle=""
Title="My Demo Title">
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal">
<Image x:Name="TitleImage"/>
<Label x:Name="TitleLabel"/>
</StackLayout>
</NavigationPage.TitleView>
Hope you can take care of the alignment and everything else. 希望您能注意对齐以及其他所有内容。 So Now using the above names you will be able to access the title image and label whenever you please!!
因此,现在使用上述名称,您将可以随时访问标题图像和标签!
I have found a solution to my problem. 我已经找到解决问题的办法。 Inside the TabbedPage, for each page that you need to have a special Navigation Bar you declare it like this:
在TabbedPage内,对于需要具有特殊导航栏的每个页面,您都需要这样声明:
<NavigationPage Title="Schedule" IconImageSource="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>
Then you edit the new page and add the <NavigationPage.TitleView/>
然后,编辑新页面并添加
<NavigationPage.TitleView/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.