ListBox Paging in Silverlight 4 using DataPager control
Posted by: Suprotim Agarwal
in Category Silverlight 2, 3, 4 and 5
Abstract: Prior to Silverlight 4, implementing paging in an application would require the developer to create controls, that would allow the user to move from one page to another. With the introduction of DataPager control in Silverlight 4, this task has become much simpler. Let us see how.
Prior to Silverlight 4, implementing paging in an application would require the developer to create controls, that would allow the user to move from one page to another. Check an old article by Malcolm Efficient Paging In Silverlight 2.0 which shows how to create and consume a WCF service in Silverlight 2.0 and use efficient server side paging using LINQ to page through event log data.
With the introduction of DataPager control in Silverlight 4, this task has become much simpler. All you need to do is add the DataPager to your page, configure a few properties and use it with the PagedCollectionView.
The DataPager control is a fully templatable data control that provides a user interface for paging through a collection of data. To provide paging functionality for an IEnumerable collection, you can wrap it in the PagedCollectionView class.
Let us see a demonstration of how to use the DataPager control to page through a ListBox control in Silverlight.
Step 1: Create a Silverlight 4 project. Drag and drop a ListBox and DataPager control from the toolbox to the UI.
Step 2: In the MainPage.xaml.cs, add an Employee class as shown below:
Step 3: Now create the PagedCollectionView using the Employee class we just created in Step 2, and assign it to the DataContext of the MainPage. Observe how we are providing paging functionality for an IEnumerable collection, by wrapping it in the PagedCollectionView class.
Step 4: The last step is to configure a few properties of the DataPager and ListBox and to specify the view as the Source of these controls
Here the PageSize property of the DataPager controls how many items appear on a single page. You can also use the LoadSize property to control how many items the DataPager will load into memory at one time. The DataPager also includes a DisplayMode property that is used to control the appearance of the DataPager control.
That’s it. Run the application and page through the ListBox.
I hope you liked the article and I thank you for viewing it. The entire source code of this article can be downloaded over here
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce the The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on .NET Standard and the upcoming C# 8.0 too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!