使用自定义标题视图更改 ContentPage 的内容

问题描述

我在标题视图中自定义标题, 我想通过按我自定义的选项卡来显示不同的内容(与其他页面)。(如下图所示) 我想知道如何更改不同页面内容...

    <ContentPage>
    <NavigationPage.TitleView>
    <Button x:Name="energy" />
    <Button x:Name="history" />
    ...
    </NavigationPage.TitleView>

    <ContentPage.Content>
//when I press energy,and content shows the Energy.xaml
//when I press history,and content shows the History.xaml
    </ContentPage.Content>
    </ContentPage>

enter image description here

解决方法

您可以使用 TabView 包中的 XamarinCommunityToolkit,这是一个示例页面,您可以在他们的示例存储库中找到它。

<ContentPage  xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
...
>
  <ContentPage.Content>
        <Grid>
            <xct:TabView
                TabStripBackgroundColor="Blue"
                TabStripHeight="40"
                TabIndicatorColor="Yellow"
                TabContentBackgroundColor="Yellow">
                <xct:TabViewItem
                    Text="Tab 1"
                    TextColor="White"
                    TextColorSelected="Yellow"
                    FontSize="12">
 <--Here you define the content of Tab1 -->
                </xct:TabViewItem>
                <xct:TabViewItem
                    Text="Tab 2"
                    TextColor="White"
                    TextColorSelected="Yellow"
                    FontSize="12">
 <--Here you define the content of Tab2 : it can be the ContentView defined in your Energy.xaml -->
                </xct:TabViewItem>
            </xct:TabView>
        </Grid>
  <ContentPage.Content>
</ContentPage>

您可以自定义很多内容,请查看 official documentation

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...