title: Is it possible to override the ItemsPresenter to use a Virtualizing StackPanel instead of a regular stack panel?
body: <p><strong>Background</strong></p>
  
  <p>I have a custom control that inherits from a TreeView and is modified to display in a data grid style.  The problem I am seeing is with performance when expanding the tree.  This is common from my research with Tree Views. Upon inspection with the WPF Performance tools I noticed that the ItemsPresenter class is using a regular Stack Panel instead of a Virtualizing Stack Panel.  </p>
  
  <p><img src="https://i.stack.imgur.com/eigPB.png" alt="enter image description here"></p>
  
  <p>Here is the section of code where the ScrollContentPresenter is used (showing in image).</p>
  
  <pre><code>&lt;ScrollContentPresenter Name="PART_ScrollContentPresenter"
        KeyboardNavigation.DirectionalNavigation="Local"
        Content="{TemplateBinding Content}"
        ContentTemplate="{TemplateBinding ContentTemplate}"
        CanContentScroll="{TemplateBinding CanContentScroll}"
        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt;
  </code></pre>
  
  <p>Here is the template being passed in.</p>
  
  <pre><code>    &lt;ControlTemplate TargetType="CommonControls:TreeListViewItem508"&gt;
      &lt;Grid &gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Border x:Name="item"&gt;
              &lt;Border Name="InnerBorder"&gt;
                  &lt;Grid Style="{StaticResource GridBackgroundStyle}"&gt;
                      &lt;Rectangle Visibility="Collapsed" Fill="#75FFFFFF" Name="UpperHighlight" /&gt;
                  &lt;/Grid&gt;
              &lt;/Border&gt;
          &lt;/Border&gt;
          &lt;ItemsPresenter Grid.Row="1" Name="ItemsHost" /&gt;
      &lt;/Grid&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is it possible to force the items presenter to use a virtualizing stack panel?</p>
  
  <p><strong>Notes</strong></p>
  
  <ul>
  <li>I have already tried wrapping the ItemsPresenter in a ScrollViewer but that gives undesired results (scroll bars for each row).</li>
  <li>I hard coded the option CanContentScroll = true as a test since this disables virtualization when its set to false.  </li>
  <li>This control is in production and used in multiple places so I don't have the option to replace / rewrite / or perform major modifications to the design at this point.  I am just looking to override this one section if possible.</li>
  </ul>
  
  <p>Any suggestions or options are much appreciated.   </p>
  
  <p>Resolved:</p>
  
  <p>I modified the template's style by adding this to the style and it switched the stack panels to virtualizing.  </p>
  
  <pre><code> &lt;Setter Property="ItemsPanel"&gt;
          &lt;Setter.Value&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;VirtualizingStackPanel /&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  </code></pre>