title: ListBox with embedded CheckBox restricting one item to be checked
body: <p>I have a ListBox containing an ItemTemplate made up of a StackPanel containing a CheckBox and a Label.  I want to allow only one list item to be checked at a time.  I am having trouble understanding how I can get this accomplished.  Here is the XAML describing the listbox:</p>
  
  <pre><code>&lt;ListBox Grid.Row="0"
           Grid.Column="0"
           Width="180"
           HorizontalAlignment="Left"
           x:Name="listboxPlayers"
           ItemsSource="{Binding Players}"
           SelectedItem="{Binding SelectedPlayer, Mode=TwoWay}"
           ScrollViewer.VerticalScrollBarVisibility="Visible"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;CheckBox IsChecked="{Binding IsDefault, Mode=TwoWay}"
                            VerticalAlignment="Center"
                            Checked="CheckBox_Checked"
                            Unchecked="CheckBox_Unchecked"/&gt;
                  &lt;Label Content="{Binding Name}"
                         VerticalAlignment="Center" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>A Player is defined as this:</p>
  
  <pre><code>public class Player
  {
      public string Name { get; set; }
      public bool IsDefault { get; set; }
  }
  </code></pre>
  
  <p>My list of <code>Players</code> is defined like this:</p>
  
  <pre><code>public ObservableCollection&lt;Player&gt; Players { get; private set; }
  </code></pre>
  
  <p>My <code>SelectedPlayer</code> is defined like this:</p>
  
  <pre><code>public static readonly DependencyProperty SelectedPlayerProperty =
      DependencyProperty.Register("SelectedPlayer", typeof(Player), typeof(MainWindow),
          new FrameworkPropertyMetadata());
  
  public Player SelectedPlayer
  {
      get { return (Player)GetValue(SelectedPlayerProperty); }
      set { SetValue(SelectedPlayerProperty, value); }
  }
  </code></pre>
  
  <p>I haven't been able to find a post or question that can help me.  I've played with using a Checked event handler for the CheckBox but I can't seem to wrap my head around how I can relate the list to the correct <code>Player</code> in the list because the ListBox doesn't adjust the <code>SelectedPlayer</code> when the CheckBox is checked or unchecked.</p>
  
  <p>Thanks very much.</p>