Поделиться через


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
Public method PagedCollectionView(IEnumerable) Initializes a new instance of the PagedCollectionView class.
Public method 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
Public property CanAddNew Gets a value that indicates whether a new item can be added to the collection.
Public property CanCancelEdit Gets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object.
Public property CanChangePage Gets a value that indicates whether the PageIndex value can change.
Public property CanFilter Gets a value that indicates whether this view supports filtering by way of the Filter property.
Public property CanGroup Gets a value that indicates whether this view supports grouping.
Public property CanRemove Gets a value that indicates whether an item can be removed from the collection.
Public property CanSort Gets a value that indicates whether this view supports sorting.
Public property Count Gets the number of records in the view after filtering, sorting, and paging.
Public property Culture Gets or sets the cultural information for any operations of the view that might differ by culture, such as sorting.
Public property CurrentAddItem Gets the item that is being added when an AddNew transaction is in progress.
Public property CurrentEditItem Gets the item in the collection that is being edited when an EditItem transaction is in progress.
Public property CurrentItem Gets the current item in the view.
Public property CurrentPosition Gets the ordinal position of the CurrentItem in the view, which might be sorted and filtered.
Public property Filter Gets or sets a callback that is used to determine whether an item is suited for inclusion in the view.
Public property GroupDescriptions Gets a collection of GroupDescription objects that describe how the items in the collection are grouped in the view.
Public property Groups Gets the top-level groups, constructed according to the descriptions specified in the GroupDescriptions property.
Public property IsAddingNew Gets a value that indicates whether an AddNew transaction is in progress.
Public property IsCurrentAfterLast Gets a value that indicates whether the CurrentItem of the view is beyond the end of the collection.
Public property IsCurrentBeforeFirst Gets a value that indicates whether the CurrentItem of the view is before the start of the collection.
Public property IsEditingItem Gets a value that indicates whether an EditItem transaction is in progress.
Public property IsEmpty Gets a value that indicates whether the view is empty.
Public property IsPageChanging Gets a value that indicates whether the page index is changing.
Public property Item Gets the item at the specified index.
Public property ItemCount Gets the minimum number of items known to be in the source collection that satisfy the current filter.
Public property NeedsRefresh Gets a value that indicates whether this view needs to be refreshed.
Public property NewItemPlaceholderPosition Gets or sets a value that indicates whether to include a new item placeholder in the collection view, and where to include it.
Public property PageIndex Gets the zero-based index of the current page.
Public property PageSize Gets or sets the number of items to display on a page.
Public property SortDescriptions Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view.
Public property SourceCollection Gets the IEnumerable collection underlying this view.
Public property TotalItemCount Gets the total number of items in the view before paging is applied.

Top

Methods

  Name Description
Public method AddNew Adds a new item to the underlying collection.
Public method CancelEdit Ends the edit transaction and, if it is possible, restores the original value of the item.
Public method CancelNew Ends the add transaction and discards the pending new item.
Public method CommitEdit Ends the edit transaction and saves the pending changes.
Public method CommitNew Ends the add transaction and saves the pending new item.
Public method Contains Returns a value that indicates whether the specified item belongs to this collection view.
Public method DeferRefresh Enters a defer cycle that you can use to merge changes to the view and delay automatic refresh.
Public method EditItem Begins an edit transaction on the specified item.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method 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.)
Public method GetEnumerator Returns an IEnumerator object that you can use to enumerate the items in the view.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetItemAt Gets the item at the specified zero-based index in this PagedCollectionView, after the source collection is filtered, sorted, and paged.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IndexOf Returns the zero-based index at which the specified item is located.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method MoveCurrentTo Sets the specified item to be the CurrentItem in the view.
Public method MoveCurrentToFirst Sets the first item in the view as the CurrentItem.
Public method MoveCurrentToLast Sets the last item in the view as the CurrentItem.
Public method MoveCurrentToNext Set the item after the CurrentItem in the view as the CurrentItem.
Public method MoveCurrentToPosition Sets the item at the specified index to be the CurrentItem in the view.
Public method MoveCurrentToPrevious Sets the item before the CurrentItem in the view as the CurrentItem.
Public method MoveToFirstPage Sets the first page as the current page.
Public method MoveToLastPage Sets the last page as the current page.
Public method MoveToNextPage Moves to the page after the current page.
Public method MoveToPage Moves to the page at the specified index.
Public method MoveToPreviousPage Moves to the page before the current page.
Public method PassesFilter Returns a value that indicates whether the specified item in the underlying collection belongs to the view after filters are applied.
Public method Refresh Re-creates the view.
Public method Remove Removes the specified item from the collection.
Public method RemoveAt Removes the item at the specified position from the collection.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Events

  Name Description
Public event CollectionChanged Occurs when the view has changed.
Public event CurrentChanged Occurs after the CurrentItem has changed.
Public event CurrentChanging Occurs when the CurrentItem is changing.
Public event PageChanged Occurs after the PageIndex has changed.
Public event PageChanging Occurs when the PageIndex is changing.
Public event PropertyChanged Occurs after a property value has changed.

Top

Extension Methods

  Name Description
Public Extension Method AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method Cast<TResult> Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method OfType<TResult> Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IEnumerable.GetEnumerator Returns an enumerator that iterates through a collection.
Explicit interface implemetationPrivate event INotifyCollectionChanged.CollectionChanged Occurs when the items list of the collection has changed, or the collection is reset.
Explicit interface implemetationPrivate event 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.