title: WPF ListBox with CheckBox data template - Binding Content property of Checkbox not working
body: <p>I am following Kelly Elias' excellent article on <a href="http://www.jarloo.com/how-to-create-a-checkedlistbox-in-wpf/" rel="nofollow noreferrer">making a WPF checkListBox</a>.</p>
  
  <p>However, in my case, I have to create my objects in code using reflection. The ListBox item source is populating appropriately and the data template is styling the ListBox correctly, resulting in a list of CheckBoxes, but no Content is being shown for the CheckBox. What am I doing wrong with the binding in my data template?</p>
  
  <p>For brevity here, see the link above for the CheckedListItem class; mine is unchanged.</p>
  
  <p><strong>The Charge class, of which we will type CheckedListItem:</strong></p>
  
  <pre><code>public class Charge
  {
      public int ChargeId;
      public int ParticipantId;
      public int Count;
      public string ChargeSectionCode;
      public string ChargeSectionNumber;
      public string ChargeSectionDescription;
      public DateTime OffenseDate;
  }
  </code></pre>
  
  <p><strong>The DataTemplate in XAML:</strong></p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;DataTemplate x:Key="checkedListBoxTemplate"&gt;
          &lt;CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Path=Item.ChargeSectionNumber}" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/UserControl.Resources&gt;
  </code></pre>
  
  <p><strong>The code behind:</strong></p>
  
  <pre><code>CaseParticipant participant = _caseParticipants.Where(q =&gt; q.ParticipantRole == content.SeedDataWherePath).FirstOrDefault();
  ObservableCollection&lt;CheckedListItem&lt;Charge&gt;&gt; Charges = new ObservableCollection&lt;CheckedListItem&lt;Charge&gt;&gt;();
  
  if (participant != null)
  {
      foreach (Charge charge in participant.Charges)
      {
          Charges.Add(new CheckedListItem&lt;Charge&gt;(charge));
      }
  
      ((ListBox)control).DataContext = Charges;
      Binding b = new Binding() { Source = Charges };
  
      ((ListBox)control).SetBinding(ListBox.ItemsSourceProperty, b);
      ((ListBox)control).ItemTemplate = (DataTemplate)Resources["checkedListBoxTemplate"];
  }
  </code></pre>
  
  <p><strong>The Result</strong></p>
  
  <p><img src="https://i.stack.imgur.com/tRltq.png" alt="4 Charges"></p>
  
  <p>The ChargeSectionNumber property of the underlying Charges have the values "11418(b)(1)", "10", "11" and "13".</p>
  
  <p>Thank you for your assistance!</p>