title: Weird issue with WPF TreeView when using mouse wheel to scroll
body: <p>So, I've been working on a legend for our map using a WPF treeview to display the groups and layers.</p>
  
  <p>I've gotten it working and displaying just fine, but when I scroll the treeview with the mousewheel, the control starts flickering and the vertical scrollbar for the tree keeps resizing up and down.</p>
  
  <p>The treeview layout is like this:</p>
  
  <ul>
  <li>Group
  
  <ul>
  <li>Layer
  
  <ul>
  <li>Layer sub items</li>
  </ul></li>
  <li>Layer
  
  <ul>
  <li>Layer sub items</li>
  </ul></li>
  <li>Layer
  
  <ul>
  <li>Layer sub items</li>
  </ul></li>
  </ul></li>
  <li>Group
  
  <ul>
  <li>Layer</li>
  <li>etc...</li>
  </ul></li>
  </ul>
  
  <p>The Group and Layer nodes are tree view items, but the layer sub items are contained within an items control.  The layer sub items are not meant to be expanded/contracted, or selected and thus must remain static under the layer node, thus the items control seemed like a sensible choice.</p>
  
  <p>When I scroll with the mouse wheel all the way to the top or bottom of the tree view, the scrollbar starts flicking and resizing, the last few elements of the items control flickers in and out of view (when it shouldn't be in view at all), and sometimes, the tree view will actually scroll back and forth.  </p>
  
  <p>If I remove the items control, everything works as it's supposed to.  And when I add it back in, it messes up. </p>
  
  <p>Also, if I grab the scroller thumb with the mouse and drag it, everything works fine. No jumping around.</p>
  
  <p>Here's the resource XAML for the control:</p>
  
  <pre><code>        &lt;views:DynamicLegendNodeTemplateSelector x:Key="LegendTemplateSelector"&gt;
          &lt;views:DynamicLegendNodeTemplateSelector.GroupTemplate&gt;
              &lt;HierarchicalDataTemplate DataType="{x:Type legend:IDynamicMapLegendGroup}"&gt;
                  &lt;HierarchicalDataTemplate.ItemsSource&gt;
                      &lt;MultiBinding Converter="{StaticResource LegendNode}"&gt;
                          &lt;Binding Path="Groups"/&gt;
                          &lt;Binding Path="LegendLayers"/&gt;
                      &lt;/MultiBinding&gt;
                  &lt;/HierarchicalDataTemplate.ItemsSource&gt;
                  &lt;Grid&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                          &lt;CheckBox Focusable="False" IsChecked="{Binding IsVisible}" VerticalAlignment="Center"&gt;
                              &lt;TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center"/&gt;
                          &lt;/CheckBox&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Grid&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/views:DynamicLegendNodeTemplateSelector.GroupTemplate&gt;
          &lt;views:DynamicLegendNodeTemplateSelector.LayerTemplate&gt;
              &lt;HierarchicalDataTemplate DataType="{x:Type legend:IDynamicMapLayerLegendItem}"&gt;
                  &lt;Grid&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="Auto"/&gt;
                          &lt;RowDefinition Height="Auto"/&gt;
                      &lt;/Grid.RowDefinitions&gt;
                      &lt;CheckBox Grid.Row="0" Focusable="False" IsChecked="{Binding IsVisible}" VerticalAlignment="Center"&gt;
                          &lt;TextBlock Text="{Binding LayerCaption}" VerticalAlignment="Center"/&gt;
                      &lt;/CheckBox&gt;
  
                      &lt;ItemsControl Grid.Row="1"
                                   Margin="16,0,0,0" 
                                  BorderThickness="0"
                                  Background="Transparent"
                                  ItemsSource="{Binding LegendItems, IsAsync=True}"
                                  HorizontalAlignment="Left"
                                  HorizontalContentAlignment="Left"
                                    MouseWheel="ItemControls_MouseWheel"
                                    ScrollViewer.CanContentScroll="False"
                                  MouseUp="ItemsControl_MouseUp"&gt;
                              &lt;ItemsControl.Template&gt;
                                  &lt;ControlTemplate&gt;
                                      &lt;ItemsPresenter/&gt;
                                  &lt;/ControlTemplate&gt;
                              &lt;/ItemsControl.Template&gt;
                              &lt;ItemsControl.ItemTemplate&gt;
                                  &lt;DataTemplate&gt;
                                      &lt;StackPanel&gt;
                                          &lt;Grid&gt;
                                              &lt;Grid.ColumnDefinitions&gt;
                                                  &lt;ColumnDefinition Width="30"/&gt;
                                                  &lt;ColumnDefinition Width="Auto"/&gt;
                                              &lt;/Grid.ColumnDefinitions&gt;
                                              &lt;Image Grid.Column="0" Width="20" Height="20" Stretch="UniformToFill" Source="{Binding Symbol}"/&gt;
                                              &lt;Label Grid.Column="1" Content="{Binding Label}"/&gt;
                                          &lt;/Grid&gt;
                                      &lt;/StackPanel&gt;
                                  &lt;/DataTemplate&gt;
                              &lt;/ItemsControl.ItemTemplate&gt;
                          &lt;/ItemsControl&gt;
                  &lt;/Grid&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/views:DynamicLegendNodeTemplateSelector.LayerTemplate&gt;
      &lt;/views:DynamicLegendNodeTemplateSelector&gt;
      &lt;Style x:Key="TreeItemStyle" TargetType="TreeViewItem"&gt;
          &lt;Setter Property="HorizontalAlignment" Value="Stretch"/&gt;
          &lt;EventSetter Event="MouseUp" Handler="TreeViewItem_MouseUp"&gt;&lt;/EventSetter&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p>And here's the treeview:</p>
  
  <pre><code>&lt;TreeView x:Name="LegendHierarchy" 
                MinWidth="200"
                ItemsSource="{Binding LegendItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:DynamicArcGisRuntimeMapLegendView}}}"
                ItemContainerStyle="{StaticResource TreeItemStyle}"
                ItemTemplateSelector="{StaticResource LegendTemplateSelector}" /&gt;
  </code></pre>
  
  <p>This code is using .NET 4.5 in Visual Studio 2015 if that matters.</p>
  
  <p>Regardless, does anyone know what might be causing the problem?</p>
  
  <p>Thanks</p>