New to Telerik UI for WPF? Download free 30-day trial

Unbound Mode

There are scenarios, in which you might want to use the RadDataPager only for its UI without passing any data to it. This scenarios will require you to use the RadDataPager's Unbound Mode feature. The use of this feature consists in setting some of the RadDataPager's properties manually and handling a few events.

The example in this topic will show you a ListBox bound to a list of integers. A RadDataPager will be used as UI to page the data, but the paging itself will be done outside of the RadDataPager via LINQ extension methods.

Here is the XAML for the example. In it you can see a ListBox and a RadDataPager with its PageSize property set. The other important thing is the event handler attached to the PageIndexChanged event.

<Grid x:Name="LayoutRoot" 
        Background="White"> 
    <Grid.RowDefinitions> 
        <RowDefinition /> 
        <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <ListBox x:Name="listBox" /> 
    <telerik:RadDataPager x:Name="radDataPager" 
                            Grid.Row="1" 
                            PageSize="10" 
                            Margin="0,10,0,0" 
                            PageIndexChanged="radDataPager_PageIndexChanged" /> 
</Grid> 

Now take a look at the code-behind. There is a simple list of integers, which will serve as a dummy data. The keypoints here are to set the ItemCount property of the DataPager to the count of your data. In this way the UI will display correct information to the user. The next point is to set the ItemsSource of the ListBox to an appropriate value and the last one is to implement the custom paging logic inside the handler for the PageIndexChanged event.

If you want to implement some logic before the PageIndex gets changed, you can attach an event handler to the PageIndexChanging event.

public partial class UnboundModeSample : UserControl 
{ 
    private List<int> data; 
    public UnboundModeSample() 
    { 
        InitializeComponent(); 
        this.data = Enumerable.Range( 0, 100 ).ToList(); 
        this.radDataPager.ItemCount = data.Count; 
        this.listBox.ItemsSource = this.data.Take( this.radDataPager.PageSize ).ToList(); 
    } 
    private void radDataPager_PageIndexChanged( object sender, PageIndexChangedEventArgs e ) 
    { 
        if ( this.data != null ) 
        { 
            this.listBox.ItemsSource = this.data.Skip( e.NewPageIndex * this.radDataPager.PageSize ).Take( this.radDataPager.PageSize ).ToList(); 
        } 
    } 
} 
Public Partial Class UnboundModeSample 
 Inherits UserControl 
 Implements IView 
 Private data As List(Of Integer) 
 Public Sub New() 
  InitializeComponent() 
  Me.data = Enumerable.Range(0, 100).ToList() 
  Me.radDataPager.ItemCount = data.Count 
  Me.listBox.ItemsSource = Me.data.Take(Me.radDataPager.PageSize).ToList() 
 End Sub 
 Private Sub radDataPager_PageIndexChanged(sender As Object, e As PageIndexChangedEventArgs) 
  If Me.data IsNot Nothing Then 
   Me.listBox.ItemsSource = Me.data.Skip(e.NewPageIndex * Me.radDataPager.PageSize).Take(Me.radDataPager.PageSize).ToList() 
  End If 
 End Sub 
End Class 

See Also

In this article