The page has been moved to GitHub

MtPivot - Pivot control for WinRT

Package: MyToolkit.Extended
Platforms: WinRT(Universal)

Notice: It is recommended to use this control only for Windows apps; Windows Phone has a native Pivot control, check out the PivotExtensions class for attached properties for the Windows Phone's Pivot control.

Used to create a pivot experience like in Windows Phone apps.

<Page xmlns:Controls="using:MyToolkit.Controls" ...>
    <controls:MtPivot>
        <controls:MtPivot.HeaderTemplate>
            <DataTemplate>
                <TextBlock d:DataContext="{d:DesignInstance controls:MtPivotItem}"
                    Text="{Binding Header}" FontSize="36" 
                    FontWeight="Light" Margin="0,-10,20,20" />
            </DataTemplate>
        </controls:MtPivot.HeaderTemplate>
        <controls:MtPivotItem Header="First">
            <TextBlock Text="First pivot content" />
        </controls:MtPivotItem>
        <controls:MtPivotItem Header="Second">
            <TextBlock Text="Second pivot content" />
        </controls:MtPivotItem>
    </controls:MtPivot>



The HeaderTemplate is not needed and a default one is provided...

A pivot item has the property Preload which is true by default. If this is set to false, the pivot is not loaded until the pivot is visible. This can be useful to improve performance when a pivot takes a long time to load...

Accessing elements within a pivot

It is not possible to name an element using the x:Name attribute and access them with the variable in the control's code-behind because the pivots are not loaded at the time the variables are loaded. However you can call the FrameworkElement.FindName(...) method with the element's name to get a reference to the element.

Note: Only elements from pivot items which have been loaded - i.e. clicked by user or Preloaded = true (preloaded by default) - can be accessed.

<Controls:MtPivot Loaded="OnPivotLoaded">
	<Controls:MtPivotItem>
		<TextBlock x:Name="MyTextBlock" />
	</Controls:MtPivotItem>
	...

The loaded event handler:

private void OnPivotLoaded(object sender, EventArgs args)
{
	var textBlock = (TextBlock)FindName("MyTextBlock");
}

Last edited Jun 3, 2015 at 9:59 PM by rsuter, version 10