2016-09-20 89 views
0

因此,我一直在使用WPF樹視圖處理地圖的圖例以顯示組和圖層。當使用鼠標滾輪滾動時WPF TreeView出現奇怪的問題

我已經得到它的工作並顯示得很好,但是當我用鼠標滾動樹形視圖時,控件開始閃爍,並且樹的垂直滾動條不斷調整大小。

樹形視圖佈局是這樣的:

  • 集團
      • 層子項目
      • 層子項目
      • 層子項目
  • 集團
    • 等...

Group和Layer節點是樹視圖項目,但圖層子項目包含在項目控件中。圖層子項不是要展開/收縮或選擇的,因此必須在圖層節點下保持靜態,因此項目控件看起來像是一個明智的選擇。

當我用鼠標滾輪一直滾動到樹視圖的頂部或底部時,滾動條開始輕彈和調整大小,項目的最後幾個元素控制閃爍進出視圖(當它不應該「根本看不到),有時,樹視圖實際上會來回滾動。

如果我刪除項目控件,一切都按照它應有的方式工作。當我把它加回來時,它會混亂起來。另外,如果我用鼠標抓住滾動條的拇指並拖動它,一切正常。沒有跳來跳去。

下面是控制資源XAML:

 <views:DynamicLegendNodeTemplateSelector x:Key="LegendTemplateSelector"> 
     <views:DynamicLegendNodeTemplateSelector.GroupTemplate> 
      <HierarchicalDataTemplate DataType="{x:Type legend:IDynamicMapLegendGroup}"> 
       <HierarchicalDataTemplate.ItemsSource> 
        <MultiBinding Converter="{StaticResource LegendNode}"> 
         <Binding Path="Groups"/> 
         <Binding Path="LegendLayers"/> 
        </MultiBinding> 
       </HierarchicalDataTemplate.ItemsSource> 
       <Grid> 
        <StackPanel Orientation="Horizontal"> 
         <CheckBox Focusable="False" IsChecked="{Binding IsVisible}" VerticalAlignment="Center"> 
          <TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center"/> 
         </CheckBox> 
        </StackPanel> 
       </Grid> 
      </HierarchicalDataTemplate> 
     </views:DynamicLegendNodeTemplateSelector.GroupTemplate> 
     <views:DynamicLegendNodeTemplateSelector.LayerTemplate> 
      <HierarchicalDataTemplate DataType="{x:Type legend:IDynamicMapLayerLegendItem}"> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
        </Grid.RowDefinitions> 
        <CheckBox Grid.Row="0" Focusable="False" IsChecked="{Binding IsVisible}" VerticalAlignment="Center"> 
         <TextBlock Text="{Binding LayerCaption}" VerticalAlignment="Center"/> 
        </CheckBox> 

        <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"> 
          <ItemsControl.Template> 
           <ControlTemplate> 
            <ItemsPresenter/> 
           </ControlTemplate> 
          </ItemsControl.Template> 
          <ItemsControl.ItemTemplate> 
           <DataTemplate> 
            <StackPanel> 
             <Grid> 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="30"/> 
               <ColumnDefinition Width="Auto"/> 
              </Grid.ColumnDefinitions> 
              <Image Grid.Column="0" Width="20" Height="20" Stretch="UniformToFill" Source="{Binding Symbol}"/> 
              <Label Grid.Column="1" Content="{Binding Label}"/> 
             </Grid> 
            </StackPanel> 
           </DataTemplate> 
          </ItemsControl.ItemTemplate> 
         </ItemsControl> 
       </Grid> 
      </HierarchicalDataTemplate> 
     </views:DynamicLegendNodeTemplateSelector.LayerTemplate> 
    </views:DynamicLegendNodeTemplateSelector> 
    <Style x:Key="TreeItemStyle" TargetType="TreeViewItem"> 
     <Setter Property="HorizontalAlignment" Value="Stretch"/> 
     <EventSetter Event="MouseUp" Handler="TreeViewItem_MouseUp"></EventSetter> 
    </Style> 

而這裏的樹視圖:

​​

如果該事項此代碼在Visual Studio 2015使用.NET 4.5。

不管有沒有人知道什麼可能會導致問題?

謝謝

回答

0

因此,它表明,試圖在一個良好的夜間睡眠是有幫助的。

顯然,所有我需要做的就是設置

VirtualizingPanel.VirtualizationMode="Recycling" 

在TreeView控件,它開始工作。

下面是完整的樹狀視圖XAML:

<TreeView x:Name="LegendHierarchy" 
       MinWidth="200" 
       ItemsSource="{Binding LegendItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:DynamicArcGisRuntimeMapLegendView}}}" 
       ItemContainerStyle="{StaticResource TreeItemStyle}" 
       ItemTemplateSelector="{StaticResource LegendTemplateSelector}" UseLayoutRounding="True" ScrollViewer.CanContentScroll="True" HorizontalContentAlignment="Stretch" 
       VirtualizingPanel.VirtualizationMode="Recycling"/> 

我希望這可以幫助別人。