title: Why is my WPF CheckBox Binding not working?
body: <p>I'm using MVVM, VS 2008, and .NET 3.5 SP1. I have a list of items, each exposing an IsSelected property. I have added a CheckBox to manage the selection/de-selection of all the items in the list (updating each item's IsSelected property). Everything is working except the IsChecked property is not being updated in the view when the PropertyChanged event fires for the CheckBox's bound control.</p>
  
  <pre><code>&lt;CheckBox
    Command="{Binding SelectAllCommand}"
    IsChecked="{Binding Path=AreAllSelected, Mode=OneWay}"
    Content="Select/deselect all identified duplicates"
    IsThreeState="True" /&gt;
  </code></pre>
  
  <p>My VM:</p>
  
  <pre><code>public class MainViewModel : BaseViewModel
  {
    public MainViewModel(ListViewModel listVM)
    {
      ListVM = listVM;
      ListVM.PropertyChanged += OnListVmChanged;
    }
  
    public ListViewModel ListVM { get; private set; }
    public ICommand SelectAllCommand { get { return ListVM.SelectAllCommand; } }
  
    public bool? AreAllSelected
    {
      get
      {
        if (ListVM == null)
          return false;
  
        return ListVM.AreAllSelected;
      }
    }
  
    private void OnListVmChanged(object sender, PropertyChangedEventArgs e)
    {
      if (e.PropertyName == "AreAllSelected")
        OnPropertyChanged("AreAllSelected");
    }
  }
  </code></pre>
  
  <p>I'm not showing the implementation of SelectAllCommand or individual item selection here, but it doesn't seem to be relevant. When the user selects a single item in the list (or clicks the problem CheckBox to select/de-select all items), I have verified that the OnPropertyChanged("AreAllSelected") line of code executes, and tracing in the debugger, can see the PropertyChanged event is subscribed to and does fire as expected. But the AreAllSelected property's get is only executed once - when the view is actually rendered. Visual Studio's Output window does not report any data binding errors, so from what I can tell, the CheckBox's IsSelected property is properly bound.</p>
  
  <p>If I replace the CheckBox with a Button:</p>
  
  <pre><code>&lt;Button Content="{Binding SelectAllText}" Command="{Binding SelectAllCommand}"/&gt;
  </code></pre>
  
  <p>and update the VM:</p>
  
  <pre><code>...
  
  public string SelectAllText
  {
    get
    {
      var msg = "Select All";
      if (ListVM != null &amp;&amp; ListVM.AreAllSelected != null &amp;&amp; ListVM.AreAllSelected.Value)
        msg = "Deselect All";
  
      return msg;
    }
  }
  
  ...
  
  private void OnListVmChanged(object sender, PropertyChangedEventArgs e)
  {
    if (e.PropertyName == "AreAllSelected")
      OnPropertyChanged("SelectAllText");
  }
  </code></pre>
  
  <p>everything works as expected - the button's text is updated as all items are selected/desected. Is there something I'm missing about the Binding on the CheckBox's IsSelected property?</p>
  
  <p>Thanks for any help!</p>