title: Handling Checked differently depending on whether it's called from a mouse click or virtualization
body: <p>I've got a WPF toolkit datagrid with virtualization turned on. Each row has a check box bound to a bool in the underlying model.</p>
  
  <p>The check boxes (in addition to the data binding) also have Checked and Unchecked handlers (!) to allow checking multiple items at once if you've click one with multiple lines selected.</p>
  
  <p>Here's the xaml:</p>
  
  <pre><code>&lt;Controls:DataGrid ItemsSource="{Binding UnderlyingData}"
                     AutoGenerateColumns="False"
                     HeadersVisibility="Column"&gt;
  
    &lt;Controls:DataGrid.Columns&gt;
      &lt;Controls:DataGridTemplateColumn Header="Use?" SortMemberPath="Use"&gt;
        &lt;Controls:DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;CheckBox Style="{StaticResource DataGridCheckBoxStyle}" IsChecked="{Binding Spike}"
                      Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" /&gt;
          &lt;/DataTemplate&gt;
        &lt;/Controls:DataGridTemplateColumn.CellTemplate&gt;
      &lt;/Controls:DataGridTemplateColumn&gt;              
    &lt;/Controls:DataGrid.Columns&gt;
  &lt;/Controls:DataGrid&gt;
  </code></pre>
  
  <p>And the Checked/Unchecked handlers:</p>
  
  <pre><code>private void CheckBox_Checked(object sender, RoutedEventArgs e)
  {
      if (!processingMultipleRows)
      {
          UpdateAllSelected(e.OriginalSource as ToggleButton);
          e.Handled = true;
      }
  }
  
  private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
  {
      if (!processingMultipleRows)
      {
          UpdateAllSelected(e.OriginalSource as ToggleButton);
          e.Handled = true;
      }
  }
  
  private void UpdateAllSelected(ToggleButton checkBox)
  {
      processingMultipleRows= true;
      var include = checkBox.IsChecked ?? false;
      tickBoxSelector.ApplyToAllSelected&lt;RowViewModel&gt;(checkBox, p =&gt; p.Use = include);
      ViewModel.ProcessUseStateChange();
      processingMultipleRows= false;
  }
  </code></pre>
  
  <p>This code works in every way except one. ViewModel.ProcessUseStateChange() is fairly slow and is currently called once whenever you toggle one or more CheckBoxes. Which is fine, but it's also called once for each new line appearing in view when you scroll the datagrid, since virtualization means new rows have to be created and their Check state must be set.</p>
  
  <p>Is there a cunning way to determine whether Checked is being called in response to a mouse click or an instantiation of a new row due to virtualization?</p>