title: ItemsControl Not Virtualizing
body: <p>I cannot get this <code>ItemsControl</code> to virtualize properly.  Debugging shows that the collection is initialized quickly, but all the items are being added to the control instead of a subset (I simply put a TracePoint in the TextBox_Initialize<code>event in the</code>UserControl` that makes up the item).</p>
  
  <p>Note: I have looked at other, similar questions, but have been unable to solve this issue with those answers.</p>
  
  <p>The ViewModel:</p>
  
  <pre><code>public class ImportInformationViewModel : CommandViewModel
  {
      public ImportInformationViewModel()
      {
  
          this.PropertyChanged += ImportInformationViewModel_PropertyChanged;
      }
  
      private ObservableCollection&lt;SingleTransactionViewModel&gt; mTransactions;
      public ReadOnlyObservableCollection&lt;SingleTransactionViewModel&gt; Transactions
      {
          get
          {
              if (mTransactions == null)
                  mTransactions = new ObservableCollection&lt;SingleTransactionViewModel&gt;();
  
              var filtered = mTransactions.Where(trans =&gt; !trans.IgnoreTransaction)
                  .OrderBy(trans =&gt; trans.DateStamp)
                  .ThenBy(trans =&gt; trans.TransactionName)
                  .ThenBy(trans =&gt; trans.TransactionDetail);
  
              return new ReadOnlyObservableCollection&lt;SingleTransactionViewModel&gt;(new ObservableCollection&lt;SingleTransactionViewModel&gt;(filtered));
          }
      }
  
      private void ImportInformationViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
      {
          if (e.PropertyName == "TransactionFileName")
          {
              if (File.Exists(mTransactionFileName))
             {
                  mTransactions.Clear();
                  // Process File (Not Shown)
                  mTransactions.Add(new SingleTransactionViewModel()
                  {
                      DateStamp = date,
                      TransactionDetail = someText;
                  });
              }
          }
  
          if (e.PropertyName != "Transactions")
              NotifyPropertyChanged("Transactions");
      }
  }
  </code></pre>
  
  <p><code>SingleTransactionViewModel</code> is just another class that implements <code>INotifyPropertyChanged</code>.  Nothing special.</p>
  
  <p>Here is the control containing the <code>ItemsControl</code></p>
  
  <pre><code>&lt;UserControl x:Class="ImportInformationView"&gt;
      &lt;UserControl.Resources&gt;
          &lt;CollectionViewSource x:Key="TransactionsData" Source="{Binding Transactions}"&gt;
              &lt;CollectionViewSource.GroupDescriptions&gt;
                  &lt;PropertyGroupDescription PropertyName="YearAndMonth" /&gt;
              &lt;/CollectionViewSource.GroupDescriptions&gt;
          &lt;/CollectionViewSource&gt;
  
          &lt;BooleanToVisibilityConverter x:Key="booleanToVisibility" /&gt;
      &lt;/UserControl.Resources&gt;
      &lt;ItemsControl ItemsSource="{Binding Source={StaticResource TransactionsData}}"
                          HorizontalAlignment="Stretch"
                          HorizontalContentAlignment="Stretch"
                          ScrollViewer.CanContentScroll="True"
                          VirtualizingStackPanel.IsVirtualizing="True"
                          VirtualizingStackPanel.VirtualizationMode="Recycling"
                          MinHeight="20"&gt;
              &lt;ItemsControl.GroupStyle&gt;
                  &lt;GroupStyle&gt;
                      &lt;GroupStyle.ContainerStyle&gt;
                          &lt;Style TargetType="{x:Type GroupItem}"&gt;
                              &lt;Setter Property="Template"&gt;
                                  &lt;Setter.Value&gt;
                                      &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                          &lt;GroupBox Padding="5" Margin="2,5"&gt;
                                              &lt;GroupBox.Header&gt;
                                                  &lt;Border Background="Black"
                                                          CornerRadius="4"&gt;
                                                      &lt;TextBlock Text="{Binding Name}" /&gt;
                                                  &lt;/Border&gt;
                                              &lt;/GroupBox.Header&gt;
                                              &lt;ItemsPresenter /&gt;
                                          &lt;/GroupBox&gt;
                                      &lt;/ControlTemplate&gt;
                                  &lt;/Setter.Value&gt;
                              &lt;/Setter&gt;
                          &lt;/Style&gt;
                      &lt;/GroupStyle.ContainerStyle&gt;
                  &lt;/GroupStyle&gt;
              &lt;/ItemsControl.GroupStyle&gt;
              &lt;ItemsControl.Template&gt;
                  &lt;ControlTemplate&gt;
                      &lt;ScrollViewer CanContentScroll="True"&gt;
                          &lt;ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /&gt;
                      &lt;/ScrollViewer&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/ItemsControl.Template&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;UniformGrid IsItemsHost="True" Columns="2" Grid.IsSharedSizeScope="True" VirtualizingStackPanel.IsVirtualizing="True" /&gt;
                      &lt;!--&lt;VirtualizingStackPanel IsItemsHost="True" /&gt;--&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;views:SingleTransactionView Margin="4,6" /&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
          &lt;/ItemsControl&gt;
      &lt;/UserControl&gt;
  </code></pre>
  
  <p>And I've boiled the <code>SingleTransactionView</code> down to something very simple:</p>
  
  <p>
      </p>
  
  <pre><code>    &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="Auto" SharedSizeGroup="ExpanderColumn" /&gt;
          &lt;ColumnDefinition Width="*" SharedSizeGroup="TransactionNameColumn" /&gt;
          &lt;ColumnDefinition Width="Auto" SharedSizeGroup="DateColumn" /&gt;
          &lt;ColumnDefinition Width="Auto" SharedSizeGroup="OptionsColumn" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
      &lt;/Grid.RowDefinitions&gt;
  
  
      &lt;TextBlock Grid.Column="1"
                 Grid.Row="0"
                 Initialized="TextBlock_Initialized"
                 Text="{Binding TransactionName}"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Center"
                 FontSize="14"
                 FontWeight="Bold"
                 Margin="4"/&gt;        
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>