title: select all checkbox in datagrid header not working properly in wpf mvvm
body: <p><a href="http://i.stack.imgur.com/V9ey3.jpg" rel="nofollow">This is what i want</a>I am working on wpf mvvm datagrid and trying to bind the select all checkbox with the view model.  It is not giving me proper result. I am giving my code details here(The xaml code and the view model code)   </p>
  
  <pre><code> &lt;DataGrid Grid.Row="0" ItemsSource="{Binding Path=UsecaseListItems}" AutoGenerateColumns="False" Name="MyDataGrid"
            CanUserAddRows="False" &gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridCheckBoxColumn Binding="{Binding IsSelected}" Width="50" &gt;
                  &lt;DataGridCheckBoxColumn.HeaderTemplate&gt;
                      &lt;DataTemplate x:Name="dtAllChkBx"&gt;
                          &lt;CheckBox Name="cbxAll" Content="All" IsChecked="{Binding Path=DataContext.AllSelected,RelativeSource={RelativeSource AncestorType=DataGrid},Mode=TwoWay}"/&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridCheckBoxColumn.HeaderTemplate&gt;
              &lt;/DataGridCheckBoxColumn&gt;
              &lt;DataGridTemplateColumn Header="Name" Width="SizeToCells" IsReadOnly="True"&gt;
                  &lt;DataGridTemplateColumn.CellTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;TextBlock Text="{Binding UsecaseName}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/DataGridTemplateColumn.CellTemplate&gt;
              &lt;/DataGridTemplateColumn&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  
  
  private bool _IsSelected;
      public bool IsSelected
      {
          get { return _IsSelected; }
          set
          {
              _IsSelected = value;
              OnPropertyChanged("IsSelected");
          }
      }
  
      private bool _AllSelected;
      public bool AllSelected
      {
          get { return _AllSelected; }
          set
          {
              _AllSelected = value;
              foreach (var reportListItemModel in UsecaseListItems)
              {
                  reportListItemModel.IsSelected = this._AllSelected;
              }
              OnPropertyChanged("IsSelected");
  
          }
      }
  
  
      private ObservableCollection&lt;UseCase&gt; _usecaseListItems = new ObservableCollection&lt;UseCase&gt;();
      public ObservableCollection&lt;UseCase&gt; UsecaseListItems
      {
          get { return _usecaseListItems; }
          set {
              _usecaseListItems = value;
              OnPropertyChanged("UsecaseListItems");
          }
      }
  </code></pre>