title: Data-Binding a WPF DataGrid Control to a System.Data.DataTable Object?
body: <p>What do I need to do to get my WPF DataGrid control to bind to a DataTable object?  </p>
  
  <p>I've been suffering over this for several days now. Even when the binding and the query both work correctly, and there is observable data in the table - nothing shows up in the data grid.  </p>
  
  <p>My XAML code resembles this:  </p>
  
  <pre><code>&lt;Window x:Class="DataGridTest.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:TK="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
      Title="Window1" Height="300" Width="300"&gt;
          &lt;Grid&gt;
              &lt;TK:DataGrid ItemsSource="{Binding Path=DTUsers}" /&gt;
          &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>My C# code-behind resembles this:<br>
  (DAO is my Data Access Object)  </p>
  
  <pre><code>public partial class Window1 : Window
  {
      public dao DAO = new dao (ConnectionString) ;
      public System.Data.DataTable DTUsers { get; set; }
  
      public Window1()
      {
          InitializeComponent();
  
          if (DAO != null)
              DTUsers = DAO.Query( @"SELECT * FROM users" );
              // Returns a DataTable object containing user records.
              // I have confirmed that this returns my data correctly.
      }
  }
  </code></pre>
  
  <p>I've checked the output, and there are no binding errors.<br>
  Why will this compile and run, but won't display any data???  </p>
  
  <p>(If you don't know where the DataGrid control is, the WPF Toolkit is available <a href="http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117" rel="nofollow noreferrer">here</a>. Install it, add a reference to WPFToolkit.dll [which will show up in the "Add Reference" dialog under ".NET"], and provide the XML namespace declaration [in my XAML above] to use the WPF DataGrid control.)</p>