PageNavigation in WPF DataPager (SfDataPager)

SfDataPager allows you to move from the current Page to various Pages.For example, when you want to move the CurrentPage to the last page directly, you can use the method MoveToLastPage() . When this method is called, the current page moves to the last page.

SfDataPager provides the following methods for page navigations.

Method Prototype Description
MoveToFirstPage MoveToFirstPage() This method moves the current page index to the first page and displays the first page data.
MoveToLastPage MoveToLastPage() This method moves the current page index to the last page and displays the last page data.
MoveToNextPage MoveToNextPage() This method moves the current page index to the next page and displays the next page data.
MoveToPreviousPage MoveToPreviousPage() This method moves the current page index to the previous page and displays the previous page data.
MoveToPage MoveToPage(int pageIndex) This method moves the current page index to the corresponding page index that is passed as an argument.

How To

How to Interact with User before Page Changes

When you are working with Paging, you may be in Edit mode or in CurrentPage. In this case, you can stop navigating the Paging by using the PageIndexChanging event before changing the page.

The following example displays the MessageBox before the PageChanging,

<Window.DataContext>
    <local:ViewModel/>
</Window.DataContext>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <sfgrid:SfDataGrid AutoGenerateColumns="True" 
                       Grid.Row="0"
                       ItemsSource="{Binding ElementName=sfDataPager,Path=PagedSource}"/>
    <datapager:SfDataPager x:Name="sfDataPager" 
                           NumericButtonCount="10"
                           Grid.Row="1"
                           PageSize="16" 
                           PageIndexChanging="sfDataPager_PageIndexChanging"
                           Source="{Binding OrdersDetails}" />
</Grid>
private void sfDataPager_PageIndexChanging(object sender, Syncfusion.UI.Xaml.Controls.DataPager.PageIndexChangingEventArgs e)
{
    MessageBoxResult result = MessageBox.Show("Do you want to change the page?", "Confirm", MessageBoxButton.YesNo);

    if (result == MessageBoxResult.No)
    {
        e.Cancel = true;
    }
}