【问题标题】:Static header in tabbed page and bottom navigation?选项卡式页面和底部导航中的静态标题?
【发布时间】:2020-11-21 18:18:42
【问题描述】:

在使用基于标签页的底部导航时,有什么方法可以创建固定在屏幕顶部的静态标题?导航时,页面向左/向右滑动,当前页眉紧随其后。标头由具有以下代码的模板创建:

<ResourceDictionary>
        <ControlTemplate x:Key="Template">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.1*" />
                </Grid.RowDefinitions>
                <BoxView Color="Black" />
                <Label 
                    Text="xyz"
                    TextColor="White"
                    FontSize="15"
                    FontFamily="Helvetet"
                    VerticalOptions="Center"
                    HorizontalOptions="Start"/>
                <ContentPresenter Grid.Row="1" VerticalOptions="Center"/>
            </Grid>
        </ControlTemplate>
    </ResourceDictionary>

应该进行哪些更改,以使标题卡在顶部,尽管页面被左右滑动?

以下是当前外观的示例

【问题讨论】:

  • 有什么建议吗?
  • 在您的情况下,您实际上需要选项卡式视图而不是选项卡式页面。选项: 1. 假标签。 2. Nuget 点赞Sharpnado.Tabs

标签: android xaml xamarin xamarin.forms xamarin.android


【解决方案1】:

您可以将 MainPage 设置为 NavigationPage,然后将其 RootPage 设置为 TabbedPage。然后你会得到一个静态的 Header 甚至切换选项卡项。

例如,App.Xaml.cs 是:

public App()
{
    InitializeComponent();
   
    MainPage = new NavigationPage(new CustomTabbedPage());
}

CustomTabbedPageXaml 是:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage  xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:AppForms19"
             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
             android:TabbedPage.ToolbarPlacement="Bottom"
             Title="Main Title"
             x:Class="AppForms19.Views.CustomTabbedPage">
    <local:MainPage Title="One" IconImageSource="icon.png"/>
    <local:SecondPage Title="Two" IconImageSource="icon.png" />
</TabbedPage>

效果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-19
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 2022-12-26
    • 1970-01-01
    • 2021-12-07
    • 2019-10-09
    相关资源
    最近更新 更多