title: How would I add Checbox dynamically into a Grid in WPF application
body: <p>I would like to add some <code>Checkbox</code> in a <code>Grid</code> control dynamically when the window is loaded in my C# Desktop application. How many times the checkbox will appear depends on the number of entries in a table. Here, I used <code>LINQ To SQL</code> class.
  The Grid control is defined in XAML.</p>
  
  <pre><code>...
  &lt;Grid Name="grid1"&gt;
     &lt;!-- here i would like to show all check box --&gt;
  &lt;/Grid&gt;
  ...
  </code></pre>
  
  <p>Code behind file:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Shapes;
  // class declaration ...
  ...
  private void course_Loaded(object sender, RoutedEventArgs e)
      {
          List&lt;Course&gt; courses = ldc.Courses.ToList();
          foreach (var c in courses)
          {
              CheckBox cb = new CheckBox();
              cb.Name=c.CourseID.ToString();
              cb.Content = c.CourseID.ToString();
              //grid1.Controls.Add(cb); does not work. what to do here?
          }
      }
  </code></pre>
  
  <p>This code is not working. Any suggession?
  Thankyou.</p>