DataGrid.ItemsSource Property


Gets or sets a collection that is used to generate the content of the control.

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

public IEnumerable ItemsSource { get; set; }
<sdk:DataGrid ItemsSource="bindingDeclaration"/>
- or -
<sdk:DataGrid ItemsSource="resourceReferenceToIEnumerable"/>

XAML Values


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


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 collection that is used to generate the content of the control. The default is null.

The following code example demonstrates how to set the AutoGenerateColumns and ItemsSource properties. This example is part of a larger example available in the DataGrid class overview.

<sdk:DataGrid x:Name="dataGrid1" 
    Height="140" Margin="0,5,0,10"
    AutoGenerateColumns="True" />            

// Set the ItemsSource to autogenerate the columns.
dataGrid1.ItemsSource = Customer.GetSampleCustomerList();

public class Customer
    public String FirstName { get; set; }
    public String LastName { get; set; }
    public String Address { get; set; }
    public Boolean IsNew { get; set; }

    // A null value for IsSubscribed can indicate 
    // "no preference" or "no response".
    public Boolean? IsSubscribed { get; set; }

    public Customer(String firstName, String lastName, 
        String address, Boolean isNew, Boolean? isSubscribed)
        this.FirstName = firstName;
        this.LastName = lastName;
        this.Address = address;
        this.IsNew = isNew; 
        this.IsSubscribed = isSubscribed;

    public static List<Customer> GetSampleCustomerList()
        return new List<Customer>(new Customer[4] {
            new Customer("A.", "Zero", 
                "12 North Third Street, Apartment 45", 
                false, true), 
            new Customer("B.", "One", 
                "34 West Fifth Street, Apartment 67", 
                false, false),
            new Customer("C.", "Two", 
                "56 East Seventh Street, Apartment 89", 
                true, null),
            new Customer("D.", "Three", 
                "78 South Ninth Street, Apartment 10", 
                true, true)


Supported in: 5, 4, 3

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

Community Additions