简体   繁体   English

如何在Xamarin.Forms的TabbedPage布局中为不同的页面设置不同的标题视图?

[英]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">...

Update: 更新:

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.

相关问题 如何在Xamarin.Forms的TabbedPage的选项卡中放置按钮? - How can I place a button in the the tabs of a TabbedPage in Xamarin.Forms? 从(不同的)class - Xamarin.Forms 更改 TabbedPage 绑定属性 - Changing TabbedPage binding property from a (different) class - Xamarin.Forms Xamarin.Forms TabbedPage - Xamarin.Forms TabbedPage Xamarin.Forms 中 TabbedPage 上的 Android.Views.InflateException - Android.Views.InflateException on TabbedPage in Xamarin.Forms 如何使用“ Xamarin.Forms”中的“ Prism.Forms”绑定视图和查看存在于不同dll中的模型? - How to bind views and view models that exist in different dlls using “Prism.Forms” in “Xamarin.Forms”? 如何自定义 TabbedPage 中栏的大小? [XAMARIN.FORMS] - How to customize the size of the bar in a TabbedPage? [XAMARIN.FORMS] Xamarin.Forms:如何更改 TabbedPage 中选项卡的 FontFamily? - Xamarin.Forms: How to change FontFamily of tabs in TabbedPage? 如何在Xamarin.Forms中自定义TabbedPage的Tab-Items? - How to customize the TabbedPage's Tab-Items in Xamarin.Forms? 如何使不同页面上的两个按钮在Xamarin.Forms中做相同的事情? - How to make two buttons on different pages do the same thing in Xamarin.Forms? Xamarin.Forms TabbedPage中的下拉菜单 - Dropdown menu in Xamarin.Forms TabbedPage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM