次の方法で共有


DataPager.Source Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the data collection that the DataPager controls paging for.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

Syntax

'Declaration
Public Property Source As IEnumerable
public IEnumerable Source { get; set; }
<sdk:DataPager Source="bindingDeclaration"/>
-or-
<sdk:DataPager Source="resourceReferenceToIEnumerable"/>

XAML Values

  • bindingDeclaration
    A Binding declaration using a {Binding ....} markup extension. For more information, see Binding Markup Extension or Binding.

  • resourceReferenceToIEnumerable
    A resource reference to an existing object of type IEnumerable from a resources collection. The resource reference must specify the desired IEnumerable by key.

Property Value

Type: System.Collections.IEnumerable
The data collection associated with this pager control.

Remarks

Dependency property identifier field: SourceProperty

The source can be any IEnumerable collection. When bound to an IEnumerable that does not implement IPagedCollectionView, the DataPager behaves as if all the data is on a single page. Setting DataPager properties will not have any effect on the control.

Typically, the source is a collection that implements IPagedCollectionView. The IPagedCollectionView provides paging functionality, and the DataPager control provides a user interface for interacting with the IPagedCollectionView. To provide paging functionality for an IEnumerable collection, you can wrap it in the PagedCollectionView class.

Examples

The following code example demonstrates how to use a PagedCollectionView as the data source for a DataPager control. The List<T> that stores the data is wrapped in a PagedCollectionView, which provides paging functionality. Both the DataPager and the ListBox that displays the data use the PagedCollectionView as their data source. This example is part of a larger example available in the DataPager class overview.

Run this sample

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
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.