Restrict Back navigation in Pivot

2019-04-17 16:54发布

问题:

I have Created a Pivot Page containing 8 Pivot items.And I Dont want my first Pivot Item to navigate backwards Mean while when it reaches the eigth page it should navigate to some other page.And also is it possible to write my own function for swipe event in pivot page.

回答1:

First, I agree with Gambit's comment that this is non-standard behavior and generally goes against a user's reasonable expectation of UI behavior. I would caution against it without a compelling reason.

That said, you can stop the looping on the pivot in the SelectionChanged event using the AddedItems and RemovedItems collections.

private void Pivot_SelectionChanged( object sender, SelectionChangedEventArgs e ) {
    if( e.AddedItems[0].Equals( PivotItem1 ) && e.RemovedItems[0].Equals( PivotItem8 ) ) {
        Pivot.SelectedIndex = 0;
    } else if( e.RemovedItems[0].Equals( PivotItem8 ) ) {
        NavigationService.Navigate( new Uri( "/NextPage.xaml", UriKind.Relative ) );
    }
}