title: How to get checked items in a WPF ListBox?
body: <p>I have a WPF ListBox where I have checkboxes, but what's the way to get the list of items that are checked?</p>
  
  <p>The ListBox is data binded to a <code>Dictionary&lt;T&gt;</code>.</p>
  
  <p>Here is the XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Window1"
          Height="300"
          Width="300"&gt;
      &lt;Grid Margin="10"&gt;
          &lt;ListBox ItemsSource="{DynamicResource Nodes}" Grid.IsSharedSizeScope="True" x:Name="MyList"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Grid&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition SharedSizeGroup="Key" /&gt;
                              &lt;ColumnDefinition SharedSizeGroup="Name" /&gt;
                              &lt;ColumnDefinition SharedSizeGroup="Id" /&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;CheckBox Name="NodeItem" Click="OnItemChecked"&gt;
                              &lt;StackPanel Orientation="Horizontal"&gt;
                                  &lt;TextBlock Margin="2" Text="{Binding Value.Name}" Grid.Column="1"/&gt;
                                  &lt;TextBlock Margin="2" Text="-" Grid.Column="2"/&gt;
                                  &lt;TextBlock Margin="2" Text="{Binding Value.Id}" Grid.Column="3"/&gt;
                              &lt;/StackPanel&gt;
                          &lt;/CheckBox&gt;
                      &lt;/Grid&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>