PagedCollectionView Class
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Represents a view for grouping, sorting, filtering, and navigating a paged data collection.
Inheritance Hierarchy
System.Object
System.Windows.Data.PagedCollectionView
Namespace: System.Windows.Data
Assembly: System.Windows.Data (in System.Windows.Data.dll)
Syntax
'Declaration
<DefaultMemberAttribute("Item")> _
Public NotInheritable Class PagedCollectionView _
Implements ICollectionView, IEnumerable, INotifyCollectionChanged, IPagedCollectionView, _
IEditableCollectionView, INotifyPropertyChanged
[DefaultMemberAttribute("Item")]
public sealed class PagedCollectionView : ICollectionView,
IEnumerable, INotifyCollectionChanged, IPagedCollectionView, IEditableCollectionView, INotifyPropertyChanged
The PagedCollectionView type exposes the following members.
Constructors
Name | Description | |
---|---|---|
PagedCollectionView(IEnumerable) | Initializes a new instance of the PagedCollectionView class. | |
PagedCollectionView(IEnumerable, Boolean, Boolean) | Initializes a new instance of the PagedCollectionView class and specifies whether the data is sorted and in group order. |
Top
Properties
Name | Description | |
---|---|---|
CanAddNew | Gets a value that indicates whether a new item can be added to the collection. | |
CanCancelEdit | Gets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object. | |
CanChangePage | Gets a value that indicates whether the PageIndex value can change. | |
CanFilter | Gets a value that indicates whether this view supports filtering by way of the Filter property. | |
CanGroup | Gets a value that indicates whether this view supports grouping. | |
CanRemove | Gets a value that indicates whether an item can be removed from the collection. | |
CanSort | Gets a value that indicates whether this view supports sorting. | |
Count | Gets the number of records in the view after filtering, sorting, and paging. | |
Culture | Gets or sets the cultural information for any operations of the view that might differ by culture, such as sorting. | |
CurrentAddItem | Gets the item that is being added when an AddNew transaction is in progress. | |
CurrentEditItem | Gets the item in the collection that is being edited when an EditItem transaction is in progress. | |
CurrentItem | Gets the current item in the view. | |
CurrentPosition | Gets the ordinal position of the CurrentItem in the view, which might be sorted and filtered. | |
Filter | Gets or sets a callback that is used to determine whether an item is suited for inclusion in the view. | |
GroupDescriptions | Gets a collection of GroupDescription objects that describe how the items in the collection are grouped in the view. | |
Groups | Gets the top-level groups, constructed according to the descriptions specified in the GroupDescriptions property. | |
IsAddingNew | Gets a value that indicates whether an AddNew transaction is in progress. | |
IsCurrentAfterLast | Gets a value that indicates whether the CurrentItem of the view is beyond the end of the collection. | |
IsCurrentBeforeFirst | Gets a value that indicates whether the CurrentItem of the view is before the start of the collection. | |
IsEditingItem | Gets a value that indicates whether an EditItem transaction is in progress. | |
IsEmpty | Gets a value that indicates whether the view is empty. | |
IsPageChanging | Gets a value that indicates whether the page index is changing. | |
Item | Gets the item at the specified index. | |
ItemCount | Gets the minimum number of items known to be in the source collection that satisfy the current filter. | |
NeedsRefresh | Gets a value that indicates whether this view needs to be refreshed. | |
NewItemPlaceholderPosition | Gets or sets a value that indicates whether to include a new item placeholder in the collection view, and where to include it. | |
PageIndex | Gets the zero-based index of the current page. | |
PageSize | Gets or sets the number of items to display on a page. | |
SortDescriptions | Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view. | |
SourceCollection | Gets the IEnumerable collection underlying this view. | |
TotalItemCount | Gets the total number of items in the view before paging is applied. |
Top
Methods
Name | Description | |
---|---|---|
AddNew | Adds a new item to the underlying collection. | |
CancelEdit | Ends the edit transaction and, if it is possible, restores the original value of the item. | |
CancelNew | Ends the add transaction and discards the pending new item. | |
CommitEdit | Ends the edit transaction and saves the pending changes. | |
CommitNew | Ends the add transaction and saves the pending new item. | |
Contains | Returns a value that indicates whether the specified item belongs to this collection view. | |
DeferRefresh | Enters a defer cycle that you can use to merge changes to the view and delay automatic refresh. | |
EditItem | Begins an edit transaction on the specified item. | |
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
GetEnumerator | Returns an IEnumerator object that you can use to enumerate the items in the view. | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetItemAt | Gets the item at the specified zero-based index in this PagedCollectionView, after the source collection is filtered, sorted, and paged. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
IndexOf | Returns the zero-based index at which the specified item is located. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
MoveCurrentTo | Sets the specified item to be the CurrentItem in the view. | |
MoveCurrentToFirst | Sets the first item in the view as the CurrentItem. | |
MoveCurrentToLast | Sets the last item in the view as the CurrentItem. | |
MoveCurrentToNext | Set the item after the CurrentItem in the view as the CurrentItem. | |
MoveCurrentToPosition | Sets the item at the specified index to be the CurrentItem in the view. | |
MoveCurrentToPrevious | Sets the item before the CurrentItem in the view as the CurrentItem. | |
MoveToFirstPage | Sets the first page as the current page. | |
MoveToLastPage | Sets the last page as the current page. | |
MoveToNextPage | Moves to the page after the current page. | |
MoveToPage | Moves to the page at the specified index. | |
MoveToPreviousPage | Moves to the page before the current page. | |
PassesFilter | Returns a value that indicates whether the specified item in the underlying collection belongs to the view after filters are applied. | |
Refresh | Re-creates the view. | |
Remove | Removes the specified item from the collection. | |
RemoveAt | Removes the item at the specified position from the collection. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Events
Name | Description | |
---|---|---|
CollectionChanged | Occurs when the view has changed. | |
CurrentChanged | Occurs after the CurrentItem has changed. | |
CurrentChanging | Occurs when the CurrentItem is changing. | |
PageChanged | Occurs after the PageIndex has changed. | |
PageChanging | Occurs when the PageIndex is changing. | |
PropertyChanged | Occurs after a property value has changed. |
Top
Extension Methods
Name | Description | |
---|---|---|
AsQueryable | Converts an IEnumerable to an IQueryable. (Defined by Queryable.) | |
Cast<TResult> | Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.) | |
OfType<TResult> | Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.) |
Top
Explicit Interface Implementations
Name | Description | |
---|---|---|
IEnumerable.GetEnumerator | Returns an enumerator that iterates through a collection. | |
INotifyCollectionChanged.CollectionChanged | Occurs when the items list of the collection has changed, or the collection is reset. | |
INotifyPropertyChanged.PropertyChanged | Occurs when a property value changes. |
Top
Remarks
You use a PagedCollectionView to provide grouping, sorting, filtering, and paging functionality for any collection that implements the IEnumerable interface. The DataPager control provides a convenient user interface for controlling paging with a PagedCollectionView.
You can think of a collection view as a layer on top of a binding source collection that allows you to navigate and display the collection based on sort, filter, and group queries, all without having to manipulate the underlying source collection itself.
Examples
The following code example demonstrates how to use a PagedCollectionView with a DataPager to page through data displayed in a ListBox. The List<T> that stores the data is wrapped in a PagedCollectionView, which provides paging functionality. Both the DataPager and the ListBox use the PagedCollectionView as their data source.
<!-- NOTE:
By convention, the sdk prefix indicates a URI-based XAML namespace declaration
for Silverlight SDK client libraries. This namespace declaration is valid for
Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace
declarations for each CLR assembly and namespace combination outside the scope
of the default Silverlight XAML namespace. For more information, see the help
topic "Prefixes and Mappings for Silverlight Libraries".
-->
<UserControl x:Class="DataPagerSample.MainPage"
xmlns:sdk="https://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" Width="400">
<StackPanel Margin="10">
<sdk:DataPager x:Name="dataPager1"
PageSize="5"
AutoEllipsis="True"
NumericButtonCount="3"
DisplayMode="FirstLastPreviousNextNumeric"
IsTotalItemCountFixed="True"/>
<ListBox x:Name="listBox1" />
</StackPanel>
</Grid>
</UserControl>
Imports System.Windows.Data
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
Dim itemList As New List(Of String)
' Generate some items to add to the list.
For index As Integer = 1 To 33
Dim sb As New System.Text.StringBuilder("Item ")
sb.Append(index.ToString)
itemList.Add(sb.ToString)
Next
' Wrap the itemList in a PagedCollectionView for paging functionality
Dim itemListView As New PagedCollectionView(itemList)
' Set the DataPager and ListBox to the same data source.
dataPager1.Source = itemListView
listBox1.ItemsSource = itemListView
End Sub
End Class
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;
namespace DataPagerSample
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
List<String> itemList = new List<String>();
// Generate some items to add to the list.
for (int i = 1; i <= 33; i++)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder("Item ");
sb.Append(i.ToString());
itemList.Add(sb.ToString());
}
// Wrap the itemList in a PagedCollectionView for paging functionality
PagedCollectionView itemListView = new PagedCollectionView(itemList);
// Set the DataPager and ListBox to the same data source.
dataPager1.Source = itemListView;
listBox1.ItemsSource = itemListView;
}
}
}
Version Information
Silverlight
Supported in: 5, 4, 3
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.