title: WPF TreeView Jumps Around
body: <p>I have a TreeView with a few hundred leaves organized in a few dozen nodes... enough nodes to require scrolling to see them all.</p>
  
  <p>Usually all works fine, but when the expanded nodes would not all fit within the ScrollViewer, clicking on a node to expand it also scrolls the whole TreeView back up to the top (hiding the just-expanded leaves until you scroll back down manually).</p>
  
  <p>This is not the same issue as <a href="https://stackoverflow.com/questions/1930154/wpf-treeview-with-isvirtualizing-true-jumps-around-when-changing-focus-and-scro">WPF TreeView with IsVirtualizing=&quot;true&quot; jumps around when changing focus and scrolling</a> because a) I'm not setting the vitualizing stack panel options; and b) This is .NET 4 (that link reports the issue only applied to 3.5).</p>
  
  <pre><code>&lt;DataTemplate x:Key="QuestionTemplate"&gt;
      &lt;Border BorderBrush="AliceBlue" BorderThickness="1"&gt;
          &lt;HeaderedContentControl HeaderTemplate="{DynamicResource QuestionHeaderTemplate}" 
                    Header="{Binding NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" IsTabStop="False" HorizontalAlignment="Left" 
                    IsEnabled="True" /&gt;                        
      &lt;/Border&gt;
  &lt;/DataTemplate&gt;
      &lt;HierarchicalDataTemplate x:Key="GroupTemplate" ItemsSource="{Binding MyData, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}" 
                                            ItemTemplate="{StaticResource MyTemplate}"&gt;                
          &lt;Border x:Name="GroupTemplateBorder" BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="10"&gt;
          &lt;HeaderedContentControl x:Name="GroupTemplateExpander" MinHeight="22" HeaderTemplate="{DynamicResource GroupHeaderTemplate}" Header="{Binding}" IsTabStop="False" 
              HorizontalAlignment="Left" VerticalContentAlignment="Center" IsEnabled="True" /&gt;                   
          &lt;/Border&gt;
      &lt;/HierarchicalDataTemplate&gt;
  
      &lt;ScrollViewer HorizontalScrollBarVisibility="Auto"&gt;
      &lt;Grid Name="gridPicker" Background="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"&gt;
      &lt;TreeView Name="treeView" MinHeight="20" ItemTemplate="{StaticResource GroupTemplate}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"&gt;
          &lt;TreeView.ItemContainerStyle&gt;
              &lt;Style TargetType="TreeViewItem"&gt;
                  &lt;Setter Property="helper:TreeViewNoSelectBehavior.IsTransparent" Value="True" /&gt;
              &lt;/Style&gt;
          &lt;/TreeView.ItemContainerStyle&gt;
      &lt;/TreeView&gt;                
      &lt;/Grid&gt;
      &lt;/ScrollViewer&gt;
  </code></pre>