title: WPF Select all CheckBox in a DataGrid
body: <p>I'm trying to select all CheckBox in a DataGrid but I didn't get any result using this code bellow</p>
  
  <p>This is the function that I'm calling when the main CheckBox is clicked</p>
  
  <pre><code>private void CheckUnCheckAll(object sender, RoutedEventArgs e)
  {
      CheckBox chkSelectAll = ((CheckBox)sender);
      if (chkSelectAll.IsChecked == true)
      {
          dgUsers.Items.OfType&lt;CheckBox&gt;().ToList().ForEach(x =&gt; x.IsChecked = true);
      }
      else
      {
          dgUsers.Items.OfType&lt;CheckBox&gt;().ToList().ForEach(x =&gt; x.IsChecked = false);
      }
  }
  </code></pre>
  
  <p>dgUsers is the DataGrid but as I realize any checkbox is found.</p>
  
  <p>This is the XAML that I'm using tho create the CheckBox in the datagrid</p>
  
  <pre><code>&lt;DataGrid.Columns&gt;
      &lt;DataGridCheckBoxColumn x:Name="col0" HeaderStyle="{StaticResource ColumnHeaderGripperStyle}"&gt;
           &lt;DataGridCheckBoxColumn.HeaderTemplate&gt;
                &lt;DataTemplate&gt;
                     &lt;CheckBox Click="CheckUnCheckAll" &gt;
                     &lt;/CheckBox&gt;
                &lt;/DataTemplate&gt;
           &lt;/DataGridCheckBoxColumn.HeaderTemplate&gt;
      &lt;/DataGridCheckBoxColumn&gt;
  &lt;DataGrid.Columns&gt;
  </code></pre>
  
  <p>And this is the picture of my DataGrid</p>
  
  <p><a href="https://i.stack.imgur.com/4eEjU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4eEjU.png" alt="enter image description here"></a></p>
  
  <p>Is there some way to select all checkbox programatically ?</p>
  
  <p><strong>Edit</strong>
  I already tried to follow <a href="https://stackoverflow.com/questions/10208004/datagrid-column-header-should-check-uncheck-checkbox-s-state-depending-upon-wh">this steps</a></p>
  
  <p>that you can  see that my code is the same there but didn't work to me </p>