title: WPF - fill data on data grid
body: <p>I have the following code and I didnt find any way how to add the data from users 
  to table .I want to do that dynamically .</p>
  
  <p>I have create WPF application and add Data Grid and button and I that when I click 
  on the button see the data on the data grid ,how should I proceed?</p>
  
  <pre><code>private void Button_Click(object sender, RoutedEventArgs e)
  {
      //get user data...
      DataTable dt = new DataTable("Users Info");
      DataGrid.ItemsSource = dt.DefaultView;
  
      foreach (var user in users)
      {
          string firstName = user.Firstname;
          string lastName = user.Lastname;
      }
  </code></pre>
  
  <p>&nbsp;</p>
  
  <p>The Xaml is: </p>
  
  <pre><code>&lt;Window
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:WPFTest01" x:Class="WPFTest01.MainWindow"
          Title="WPF_DEMO_Main" Height="350" Width="525"&gt;
  
      &lt;Grid x:Name="Grid" Background="#FF1BA1E2"&gt;
          &lt;DataGrid x:Name="DataGrid" HorizontalAlignment="Left" Margin="65,60,0,0" VerticalAlignment="Top" Height="185" Width="385" SelectionChanged="DataGrid_SelectionChanged_1"/&gt;
          &lt;Button Content="Button" HorizontalAlignment="Left" Margin="390,280,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I have tried with some of this code without success :(</p>
  
  <pre><code>//dt.Columns.Add("First Name", typeof(string));
  //dt.Columns.Add("Last Name", typeof(string));
  
  //DataSet ds = new DataSet();
  
  //ds.Tables.Add(dt);
  </code></pre>