CollectionViewSource.Source Property

Gets or sets the collection object from which to create this view.

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

Public Property Source As Object
    <Object .../>
<collectionViewSource Source="myCollection"/>

XAML Values




An existing collection. To refer to an existing collection, use the StaticResource Markup Extension.

Property Value

Type: System.Object
The collection object from which to create this view. The default is Nothing.


The specified value when setting this property is not Nothing or an IEnumerable implementation.


The specified value when setting this property is an ICollectionView implementation.


The specified value implements ICollectionViewFactory but its CreateView method returns an ICollectionView with one or more of the following inconsistencies:

When you set this property, a view is generated automatically unless the source collection implements ICollectionViewFactory. Otherwise, the view is retrieved through the CreateView method.

You can retrieve the view through the View property.

Version Notes

Silverlight 3 does not support the ICollectionViewFactory interface.

The following code example demonstrates the use of this property in XAML to apply sorting to a data source. The data is also defined in XAML to enable you to see the effects of the CollectionViewSource in the Silverlight Designer in Visual Studio 2010.

This example uses the Customer and CustomerCollection classes defined in Walkthrough: Using Sample Data in the Silverlight Designer. The walkthrough also describes how to use design-time attributes to display sample data in the Silverlight Designer.

<UserControl x:Class="CollectionViewSourceExample.MainPage"
  mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400" >


    <local:CustomerCollection x:Key="customerSampleData" >
      <local:Customer FirstName="Syed" LastName="Abbas" Age="23" 
        CustomerID="E7181DC6-3F9E-45A4-A5F7-AC0B119D1FD8" />
      <local:Customer FirstName="Brenda" LastName="Diaz" Age="55" 
        CustomerID="BB638D72-8B72-495A-B0F9-79F37964BBAE" />
      <local:Customer FirstName="Lori" LastName="Kane" Age="17" 
        CustomerID="B168D811-5548-4D28-8171-318F9A4D7219" />

    <CollectionViewSource x:Name="dataSource" 
      Source="{StaticResource customerSampleData}">
        <compMod:SortDescription PropertyName="Age" Direction="Ascending"/>

  <Grid x:Name="LayoutRoot" Background="White">
    <sdk:DataGrid ItemsSource="{Binding Source={StaticResource dataSource}}" />



Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.