New developer
New developer

Reputation: 153

Nested Pivot control

Is it Possible to have a nested Pivot control in WP7. Like I was a pivot page 1,2,3 and inside 1, I want to have page a,b,c. Is it possible to control it only within MainPage.xaml?

I want the old pivot 1,2,3 to disappear on click on 1 and instead have a,b,c as the main pivot headers. Is it possible?

Upvotes: 0

Views: 815

Answers (1)

Den
Den

Reputation: 16826

This scenario is generally possible. However, I would highly recommend not to do it, as it will confuse the user and will add you more work to do (as per handling navigation between pivots instead of pages). So let's say I have a sample Pivot control:

<controls:Pivot x:Name="HostPivot" Title="MY APPLICATION">
<controls:PivotItem x:Name="MainPivot" Header="first">
    <controls:Pivot x:Name="sPivot" Title="Secondary Pivot">
        <controls:PivotItem x:Name="sPivotItem" Header="inside1"></controls:PivotItem>
        <controls:PivotItem Header="inside2"></controls:PivotItem>
        <controls:PivotItem Header="inside3"></controls:PivotItem>
    </controls:Pivot>
</controls:PivotItem>

<controls:PivotItem x:Name="SecondaryPivot" Header="second"> 
</controls:PivotItem>
</controls:Pivot>

Whenever I will try to navigate inside the second Pivot control (with the active host), HostPivot will intercept the manipulation and move to the next pivot item inside it instead of sPivot.

What to do in this case? Detect the manipulation:

sPivot.ManipulationStarted += new EventHandler<ManipulationStartedEventArgs>(sPivot_ManipulationStarted);

So you will eventually have this piece to replace the host pivot with the secondary one:

void sPivot_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
    if (MainPivot.Content != null)
    {
        MainPivot.Content = null;
        LayoutRoot.Children.Remove(HostPivot);
        LayoutRoot.Children.Add(sPivot);
    }
}

You'd have to remove the secondary Pivot control from the set of child controls of the first PivotItem in the host Pivot control and add it to the main grid (LayoutRoot).

This will eventually raise the question - do you really want to implement the navigation this way (between pivots) when it's clearly easier and more efficient to navigate between separate PhoneApplicationPage entitites.

Upvotes: 1

Related Questions