title: WPF GridView with Multiple Checkbox Columns and Select All Column Header
body: <p>I have a ListView containing several GridViewColumns. Several of the columns are checkboxes. Each column header consists of a checkbox as well, with the intention of checking/unchecking all the checkboxes in that column. Each row's checkboxes are bound to properties in my view model. I've seen several postings where the scenario is a single column of checkboxes, but none of those solutions will work for me, as I have 4 columns of checkboxes. I also need to persist the state of the selections from one visit to the next (all, some or none of the checkboxes in a column could be checked).</p>
  
  <p>Here's an abbreviated version of the XAML for my ListView:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ListView ItemsSource="{Binding AveragingParameters}"&gt;
    &lt;ListView.View&gt;
      &lt;GridView AllowsColumnReorder="False"&gt;
  
        &lt;GridViewColumn Header="Parameter"&gt;
          &lt;GridViewColumn.CellTemplate&gt;
            &lt;DataTemplate&gt;
              &lt;DockPanel&gt;
                &lt;TextBlock Text="{Binding Name}" /&gt;
              &lt;/DockPanel&gt;
            &lt;/DataTemplate&gt;
          &lt;/GridViewColumn.CellTemplate&gt;
        &lt;/GridViewColumn&gt;
  
        &lt;GridViewColumn&gt;
          &lt;GridViewColumn.CellTemplate&gt;
            &lt;DataTemplate&gt;
              &lt;Grid HorizontalAlignment="Stretch"&gt;
                &lt;CheckBox  x:Name="chkAvg" IsChecked="{Binding CalcAverage}" /&gt;
              &lt;/Grid&gt;
            &lt;/DataTemplate&gt;
          &lt;/GridViewColumn.CellTemplate&gt;
          &lt;Grid&gt;
            &lt;CheckBox x:Name="chkAvgSelectAll" Content="Avg" ToolTip="Select All" /&gt;
          &lt;/Grid&gt;
        &lt;/GridViewColumn&gt;
  
        &lt;GridViewColumn&gt;
          &lt;GridViewColumn.CellTemplate&gt;
            &lt;DataTemplate&gt;
              &lt;Grid HorizontalAlignment="Stretch"&gt;
                &lt;CheckBox  x:Name="chkMin" IsChecked="{Binding CalMin}" /&gt;
              &lt;/Grid&gt;
            &lt;/DataTemplate&gt;
          &lt;/GridViewColumn.CellTemplate&gt;
          &lt;Grid&gt;
            &lt;CheckBox x:Name="chkMinSelectAll" Content="Min" ToolTip="Select All" /&gt;
          &lt;/Grid&gt;
        &lt;/GridViewColumn&gt;
  
      &lt;/GridView&gt;
    &lt;/ListView.View&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p>I've tried using Commands and Command Parameters, PropertyChanged events on the Checked property, and handling the Checked event in my code behind, but nothing gives me enough information to know what to change in the collection I'm bound to.</p>
  
  <p>I suppose I could create a separate event handler for each, but I'd like to be able to handle this in a single event handler if possible, because eventually I will be creating a custom control that is a bit more malluable in terms of the columns displayed.</p>
  
  <p>Thanks in advance</p>