问题描述
我在标题视图中自定义标题, 我想通过按我自定义的选项卡来显示不同的内容(与其他页面)。(如下图所示) 我想知道如何更改不同页面的内容...
<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>
解决方法
您可以使用 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。