title: ListBox.SelectedItem and ListBoxItem.IsSelected get out of sync
body: <p>I have a listbox defined in a WPF window as follows:</p>
  
  <pre><code>&lt;ListBox ItemsSource="{Binding Values}" SelectedItem="{Binding SelectedValue}"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;Border BorderThickness="1" BorderBrush="Black" Margin="5"&gt;
                  &lt;StackPanel Margin="5"&gt;
                      &lt;TextBlock FontWeight="Bold" Text="{Binding}"/&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;Label&gt;Is Selected: &lt;/Label&gt;
                          &lt;TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}"/&gt;
                      &lt;/StackPanel&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;Label&gt;Selected Item:&lt;/Label&gt;
                          &lt;TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=ListBox}, Path=SelectedItem}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/StackPanel&gt;
              &lt;/Border&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>And on the view model:</p>
  
  <pre><code>    private string selectedValue;
  
      private ObservableCollection&lt;string&gt; values;
  
      public MainWindowViewModel()
      {
          this.values = new ObservableCollection&lt;string&gt;(new[] { "Fish", "Chips", "Peas" });
      }
  
      public ObservableCollection&lt;string&gt; Values
      {
          get
          {
              return this.values;
          }
      }
  
      public string SelectedValue
      {
          get { return this.selectedValue; }
          set
          {
              this.selectedValue = value;
  
              if (value == "Peas")
              {
                  this.SelectedValue = null;
              }
  
              this.OnPropertyChanged();
          }
      }
  </code></pre>
  
  <p>Each entry in the listbox displays its text and also a pair of textblocks indicating whether the listboxitem's IsSelected is set, and also what the current SelectedItem of the listbox is.</p>
  
  <p>Everything works fine, until the "Peas" option is selected. 
  The view model has a piece of code which sets the viewmodel's <code>SelectedValue</code> to null in that instance, which in turn sets the listbox's SelectedItem property to null (overriding the fact that the user just clicked "Peas"). </p>
  
  <p>However, the ListBoxItem's <code>IsSelected</code> property for "Peas" does not get set to false even though the ListBox now has no selected item.</p>
  
  <p>Any suggestions how to force the ListBoxItem to have <code>IsSelected=false</code> as well?</p>