Rico Suter edited this page Jul 8, 2015 · 3 revisions
  • Package: MyToolkit.Extended
  • Platforms: WinRT, UWP

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" ...>
                <TextBlock d:DataContext="{d:DesignInstance controls:MtPivotItem}"
                    Text="{Binding Header}" FontSize="36" 
                    FontWeight="Light" Margin="0,-10,20,20" />
        <controls:MtPivotItem Header="First">
            <TextBlock Text="First pivot content" />
        <controls:MtPivotItem Header="Second">
            <TextBlock Text="Second pivot content" />

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">
        <TextBlock x:Name="MyTextBlock" />

The loaded event handler:

private void OnPivotLoaded(object sender, EventArgs args)
    var textBlock = (TextBlock)FindName("MyTextBlock");
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.