title: WPF ListBoxItem selection problem
body: <p>I have a listbox where the items contain checkboxes:</p>
  
  <pre><code>&lt;ListBox Style="{StaticResource CheckBoxListStyle}" Name="EditListBox"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;CheckBox Click="Checkbox_Click" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" Content="{Binding Path=DisplayText}" /&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>The problem I'm having is that when I click on the checkbox or its content, the parent ListBoxItem does not get selected.  If I click on the white space next to the checkbox, the ListBoxItem does get selected.</p>
  
  <p>The behavior that I'm trying to get is to be able to select one or many items in the list and use the spacebar to toggle the checkboxes on and off.</p>
  
  <p>Some more info:</p>
  
  <pre><code>private void Checkbox_Click(object sender, RoutedEventArgs e)
  {
      CheckBox chkBox = e.OriginalSource as CheckBox;
  }
  </code></pre>
  
  <p>In the code above when I click on a checkbox, e.Handled is false and chkBox.Parent is null.</p>
  
  <p>Kent's answer put me down the right path, here's what I ended up with:</p>
  
  <pre><code>&lt;ListBox Style="{StaticResource CheckBoxListStyle}" Name="EditListBox" PreviewKeyDown="ListBox_PreviewKeyDown"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;CheckBox IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" /&gt;
                  &lt;TextBlock Text="{Binding DisplayText}"/&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>I had to use PreviewKeyDown because by default when you hit the spacebar in a list box, it deselects everything except for the most recently selected item.</p>