Pivot control is used to navigate between the pages in your app easily. To navigate to other pages in the control, just click Pivot header or swipe left or right.
Pivot Header: Pivot Item header is the title of the item and we can use an icon, text or both.
Pivot items: Pivot Item is a collection of the items of any type. We can add any item in the pivot items.
Pivot control is easy to implement to the Pivot control. You just need to add the following code for the simple text header.
- <Pivot Title="Pivot Control Sample">
- <Pivot.Items>
- <PivotItem Header="Pivot Item 1">
- <Grid>
- <TextBlock Text="Item 1 Content" /> </Grid>
- </PivotItem>
- <PivotItem Header="Pivot Item 2">
- <StackPanel>
- <TextBlock Text="Item 2 Content" />
- <TextBlock Text="http://windowsapptutorials.wordpress.com/" FontStyle="Italic" Foreground="#FF2975D1"></TextBlock>
- </StackPanel>
- </PivotItem>
- </Pivot.Items>
- </Pivot>
Now, run the app and see the output looks like the following image:
Now see how to set image or customized Pivot Item Header Customizations of Pivot is required and we need to use DataTemplates. The Pivot control provides a property called TitleTemplete and HeaderTemplate. Using this template title and header of the pivot items, we can define our customized data. For it, we need to define our resource, using the code, given below:
- <Page.Resources>
- <DataTemplate x:Key="HeaderTemplate">
- <StackPanel>
- <Image Width="70" Height="50" Source="{Binding}"></Image>
- </StackPanel>
- </DataTemplate>
- </Page.Resources>
Now, add the code, given below, to set the Pivot header as an image.
- <Pivot HeaderTemplate="{StaticResource HeaderTemplate}">
- <PivotItem Header="Assets/W101.png" Margin="12,10,12,0">
- <TextBlock Text="Item 1"></TextBlock>
- </PivotItem>
- <PivotItem Header="Assets/W102.png" Margin="12,10,12,0">
- <TextBlock Text="Item 2"></TextBlock>
- </PivotItem>
- </Pivot>
Now, run the app and see the output, given below:
For more information on Windows 10 UWP, refer to my e-book:
Windows 10 UWP E-book