2016-09-20 27 views
0

私は、WPFツリービューを使用してグループとレイヤーを表示するためのマップの凡例を作成しています。マウスホイールを使ってスクロールするときのWPF TreeViewの奇妙な問題

私はそれをうまく動作させて表示していますが、マウスホイールでツリービューをスクロールすると、コントロールがちらつき始め、ツリーの垂直スクロールバーが上下にサイズ変更を続けます。

ツリービューのレイアウトは、このようなものです:

  • グループ
    • レイヤ
      • レイヤサブ項目
    • レイヤ
      • レイヤサブ項目
    • レイヤ
      • レイヤサブ項目
  • グループ
    • レイヤ
    • 等...

グループおよびレイヤーノードはツリービューアイテムですが、レイヤーサブアイテムはアイテムコントロール内に含まれています。レイヤのサブアイテムは、展開/縮小、または選択されていないため、レイヤノードの下に静止していなければなりません。したがって、アイテムコントロールは賢明な選択のように見えます。

ツリービューの上部または下部にマウスホイールをスクロールすると、スクロールバーがフリックしてサイズ変更され、アイテムの最後のいくつかの要素が点滅し、点滅します(点滅したり、実際にはツリービューは前後にスクロールします。

アイテムコントロールを削除すると、すべて正常に動作します。そして、私がそれを戻すと、それは壊れてしまいます。

また、マウスでスクロール・サムをつかんでドラッグすると、すべて正常に動作します。周りには飛びません。

ここ制御のためのリソース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

だから、それは良い夜の睡眠の試みが有益であることを示すことを行きます。

はどうやら、私がしなければならなかったすべては、TreeViewコントロールで

VirtualizingPanel.VirtualizationMode="Recycling" 

を設定し、それが作業を開始します。

はここで完全なツリービューの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"/> 

私は、これは他の人に役立ちます願っています。