title: How to get Selected items in WPF CheckBox ListBox
body: <p>Am Using the checkbox in listbox items, how to get the selected checkboxes from the list</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding NameList}"  HorizontalAlignment="Left" Margin="16,68,0,12" Name="listBox1" Width="156" IsEnabled="True" SelectionMode="Multiple" Focusable="True" IsHitTestVisible="True" IsTextSearchEnabled="False" FontSize="12" Padding="5" SelectionChanged="listBox1_SelectionChanged"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt; 
                          &lt;StackPanel Orientation="Horizontal"&gt;                      
                                 &lt;CheckBox Content="{Binding Path=CNames}" /&gt;
                          &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
  </code></pre>
  
  <p>I tried to loop thru the selected items in the listboxitems, but it throws exception in listboxitem </p>
  
  <pre><code> private void btnSelected(object sender, RoutedEventArgs e)
      {
          foreach (ListBoxItem item in listBox1.Items)
          {
              if (item.ToString() == "true")
              {
                  MessageBox.Show(item.Content.ToString());
              }
          }
      }
  </code></pre>