title: C# WPF ListBox Checkbox Binding IsChecked to a Field and IsSelected?
body: <p>I'm trying to bind a CheckBox to a field but also trigger the checkbox's IsSelected.  </p>
  
  <p>Here is the ListBox setup that is working with the Binding to data</p>
  
  <pre><code>&lt;ListBox x:Name="lstExclude"  Grid.Column="2" SelectionMode="Single" &gt;
    &lt;ListBox.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;CheckBox  Content="{Binding Text}" 
            IsChecked="{Binding Checked ,Mode=TwoWay}"/&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>And here is the code associated with the binding </p>
  
  <pre><code>public MainWindow()
  {
      InitializeComponent();
  
      List&lt;CheckBoxListItem&gt; items1 = new List&lt;CheckBoxListItem&gt;();
      items1.Add(new CheckBoxListItem(true, “home”));
      items1.Add(new CheckBoxListItem(false, “work”));
      items1.Add(new CheckBoxListItem(true, “cell”));
      lstExclude.ItemsSource = items1;
  }
  
  public class CheckBoxListItem
  {
     public bool Checked { get; set; }
     public string Text { get; set; }
  
     public CheckBoxListItem(bool ch, string text)
     {
       Checked = ch;
       Text = text;
      }
  }
  </code></pre>
  
  <p>This binds the checkbox checked value correctly, but if I click the checkbox (checked or unchecked), I want it to select the item, so I tried doing it this way</p>
  
  <pre><code>&lt;ListBox x:Name="lstExclude"  Grid.Column="2" SelectionMode="Single" &gt;
    &lt;ListBox.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;CheckBox  Content="{Binding Text}" 
            IsChecked="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}"/&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>So this gives me the results of clicking the checkbox (check or uncheck) and it will select the item.  The problem is now the Checked field is not bound when I add the items.</p>
  
  <p>How can you get the checkbox to be both bound to the Checked field AND still have the IsSelected work?</p>