title: Bindings on Datagrids in code Behind
body: <p>I'm working on a cookbook for myself, written in WPF/C#.
  Additionally I'm new to Data Bindings.</p>
  
  <p>My Problem is, I want to generate a Datagrid in a TabItem on runtime in code behind, including Bindings. I can't set a Datagrid at XAML because I want to create all TabItems dynamically.</p>
  
  <p>Following Code so far:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;UniformGrid Columns="2" Rows="1"&gt;
  &lt;TabControl Name="TabControl" TabStripPlacement="Left"/&gt;
    &lt;TabItem Header= "first dish" Name = "firstdish"/&gt;
  &lt;/UniformGrid&gt;
  </code></pre>
  
  <p>XAML.cs for generation:</p>
  
  <pre><code>//New Grid
          var Grid = new DataGrid();
  
          //Start Test list creation with three items
          var TestList = new List&lt;Receipt&gt;();
  
          //Set binding
          Grid.ItemsSource = TestList;
  
          var Rec = new Receipt();
          Rec.Creator = "DaJohn1";
          Rec.ID = 1;
          Rec.Title = "TestReceipt1";
  
          var Rec2 = new Receipt();
          Rec2.Creator = "DaJohn2";
          Rec2.ID = 2;
          Rec2.Title = "TestReceipt2";
  
          var Rec3 = new Receipt();
          Rec3.Creator = "DaJohn3";
          Rec3.ID = 3;
          Rec3.Title = "TestReceipt3";
  
          TestList.Add(Rec);
          TestList.Add(Rec2);
          TestList.Add(Rec3);
          //End Test list creation
  
          //Add Column
          var SingleColumn = new DataGridTextColumn();
          Grid.Columns.Add(SingleColumn);
          SingleColumn.Binding = new Binding("Creator");
          SingleColumn.Header = "Creator";
  
          //Add Column
          var SingleColumn2 = new DataGridTextColumn();
          Grid.Columns.Add(SingleColumn2);
          SingleColumn2.Binding = new Binding("Title");
          SingleColumn2.Header = "Title";
  
          //Set tabitem content to datagrid
          firstdish.Content = Grid;
  </code></pre>
  
  <p>All I'm getting is an datagrid with four rows (looks like the count of Items is right), which are all empty, no data to be seen.
  I'm staring at this since last Weeks Monday and can't find an answer anywhere.</p>
  
  <p>Thanks for any ideas and solutions.</p>