简体   繁体   中英

Change the ContentPage's content with customize titleview

I make a customize title in the titleview, and I want to show different content(with other pages) by pressing the tabs I customize.(like pic shows below) I am wondering how to change the content with different pages...

    <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>

在此处输入图像描述

You can use TabView from XamarinCommunityToolkit package, here is a sample page you can find it in their sample repo.

<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>

There is plenty of stuff you can customize take a look at the official documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM