title: Why isn't my WPF Datagrid showing data?
body: <p>This <a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-datagrid-feature-walkthrough.aspx" rel="noreferrer">walkthrough</a> says you can create a WPF datagrid in one line but doesn't give a full example.</p>
  
  <p>So I created an example using a generic list and connected it to the WPF datagrid, but it doesn't show any data.</p>
  
  <p>What do I need to change on the code below to get it to show data in the datagrid?</p>
  
  <h2>ANSWER:</h2>
  
  <p>This code works now:</p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="TestDatagrid345.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
      xmlns:local="clr-namespace:TestDatagrid345"
      Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"&gt;
      &lt;StackPanel&gt;
          &lt;toolkit:DataGrid ItemsSource="{Binding}"/&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code Behind:</strong></p>
  
  <pre><code>using System.Collections.Generic;
  using System.Windows;
  
  namespace TestDatagrid345
  {
      public partial class Window1 : Window
      {
          private List&lt;Customer&gt; _customers = new List&lt;Customer&gt;();
          public List&lt;Customer&gt; Customers { get { return _customers; }}
  
          public Window1()
          {
              InitializeComponent();
          }
  
          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
              DataContext = Customers;
  
              Customers.Add(new Customer { FirstName = "Tom", LastName = "Jones" });
              Customers.Add(new Customer { FirstName = "Joe", LastName = "Thompson" });
              Customers.Add(new Customer { FirstName = "Jill", LastName = "Smith" });
          }
      }
  }
  </code></pre>