title: get all selected items from wpf checkbox list give me error
body: <p>I have <code>ListBox</code> with checked box as following, and it binding its data from <code>SQL server database</code>. I want to get selected items value When I run this but I got this error:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Data.DataRowView' to type 
    'System.Windows.Controls.CheckBox'.</p>
  </blockquote>
  
  <p>This is code:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;DataTemplate x:Key="NameColumnTemplate"&gt;
          &lt;CheckBox Height="20" FontFamily="Arial" FontSize="14" Content="{Binding Path=PermissionDescription}" Tag="{Binding PermissionID}" HorizontalAlignment="Stretch" VerticalAlignment="Center" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  
  &lt;Grid&gt;
      &lt;ListBox HorizontalAlignment="Stretch" Margin="12,12,136,21" Name="lstEmployees" 
           VerticalAlignment="Stretch" ItemsSource="{Binding Tables[0]}"  
           ItemTemplate="{StaticResource NameColumnTemplate}" 
           ScrollViewer.VerticalScrollBarVisibility="Auto" removed="{x:Null}"
           BorderBrush="#FFAD7F30"  
           SelectionChanged="lst_SelectionChanged" CheckBox.Click="lst_SelectionChanged"/&gt;
  
      &lt;Button Content="listbox" Height="23" HorizontalAlignment="Left" Margin="214,207,0,0" Name="btnShowSelectedItems" VerticalAlignment="Top" Width="75" Click="btnShowSelectedItems_Click" /&gt;
  &lt;/Grid&gt;
  
  public Window2()
  {
      InitializeComponent();
      // bind data 
      lstEmployees.DataContext = SelJobsCat();
  }
  
  private void btnShowSelectedItems_Click(object sender, RoutedEventArgs e)
  {
      foreach (CheckBox item in lstEmployees.Items)
      {
          if (item.IsChecked == true)
          {
              System.Windows.MessageBox.Show((item.Content + " is checked."));
          }
      }
  }
  
  private void lst_SelectionChanged(object sender, RoutedEventArgs e)
  {
      if (e.OriginalSource is CheckBox)
      {
          lstEmployees.SelectedItem = e.OriginalSource;
      }
  
      if (lstEmployees.SelectedItem == null) return;
  
      Console.WriteLine(lstEmployees.SelectedIndex);
      Console.WriteLine(((CheckBox)lstEmployees.SelectedItem).IsChecked);
   }
  </code></pre>
  
  <p>Where is my error please, Thanks.</p>