Pivot Control

The Pivot control provides a way to navigate through different content sections using a set of tabs. It's commonly used to organize information into distinct categories, making it easier for users to find what they're looking for.

WinUI Pivot Control Example

Key Features

When to Use the Pivot Control

Use the Pivot control when:

Basic Usage (XAML)

Here's a simple example of how to implement a Pivot control in XAML:


<Pivot>
    <PivotItem Header="Overview">
        <TextBlock Text="This is the overview content." FontSize="20"/>
    </PivotItem>
    <PivotItem Header="Details">
        <StackPanel>
            <TextBlock Text="Details about the item:" Margin="0,10,0,0"/>
            <ListView ItemsSource="{x:Bind DetailItems}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding}" Padding="5"/>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackPanel>
    </PivotItem>
    <PivotItem Header="Settings">
        <TextBlock Text="Configuration options go here." FontSize="20"/>
    </PivotItem>
</Pivot>
                

Properties

Property Description Default
SelectedIndex Gets or sets the index of the currently selected pivot item. 0
SelectedItem Gets or sets the currently selected pivot item. null
Items Gets the collection of PivotItems within the Pivot control. Empty collection
HeaderTemplate Defines the data template for the header of each PivotItem. null
IsHeaderItemsCarouselEnabled Indicates whether the headers can be scrolled horizontally when they exceed the available space. true

PivotItem

Each pivot section is represented by a PivotItem:

Common Scenarios

With Icons in Headers

You can add icons to your pivot headers for a more visual experience:


<Pivot>
    <PivotItem Header="Home">
        <PivotItem.HeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <SymbolIcon Symbol="Home" />
                    <TextBlock Text="{Binding}" Margin="8,0,0,0"/>
                </StackPanel>
            </DataTemplate>
        </PivotItem.HeaderTemplate>
        <!-- Home Content -->
    </PivotItem>
    <PivotItem Header="Search">
        <PivotItem.HeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <SymbolIcon Symbol="Find" />
                    <TextBlock Text="{Binding}" Margin="8,0,0,0"/>
                </StackPanel>
            </DataTemplate>
        </PivotItem.HeaderTemplate>
        <!-- Search Content -->
    </PivotItem>
</Pivot>
                
Note: Ensure you have the necessary namespaces imported in your XAML file to use SymbolIcon and StackPanel.

Dynamic Content Loading

You might want to load content for a PivotItem only when it becomes visible to improve performance. This can be achieved by using events or binding to properties that conditionally render content.

Accessibility Considerations

The Pivot control inherently provides keyboard navigation (Tab to navigate headers, Arrow keys to switch between them). Ensure that the content within each PivotItem is also accessible and clearly labeled.

Tip: Use descriptive text for your pivot headers. If using icons, always provide alternative text or associate them with the header text for screen readers.

Related Topics