我创建了一个支持虚拟化的MultiSelection树视图。 当我尝试扩展它并添加列时,虚拟化就会停止工作。
使用Snoop,并依赖以前的帖子,我尝试设置VirtualizingStackPanel.IsVirtualizing =" True"和ScrollViewer.CanContentScroll =" True"在树和卷轴上。不好......
工作树的xaml非常简单 - 没有样式(除了扩展所有项目)我将新树(有列)放在旧树(同一主网格)旁边。它的格式如下:
<window:TreeListView Grid.Row="0" ItemsSource="{Binding Path=Coverages}" x:Name="MainTree" Margin="4,0,0,0" GridViewColumnHeader.Click="TreeListView_ColumnHeaderClicked" Loaded="MainTree_OnLoaded" Unloaded="MainTree_OnUnloaded" PreviewMouseRightButtonUp="ShowContextMenu" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" >
<window:TreeListView.Resources>
<HierarchicalDataTemplate DataType="{x:Type window:CoverageSummary}" ItemsSource="{Binding CoveredProjects}" />
<HierarchicalDataTemplate DataType="{x:Type window:ProjectCoverageSummary}" ItemsSource="{Binding CoveredPrograms}" />
<HierarchicalDataTemplate DataType="{x:Type window:ProgramCoverageSummary}" ItemsSource="{Binding ElementsSummaryList}" />
</window:TreeListView.Resources>
<window:TreeListView.Columns>
<GridViewColumn>
<GridViewColumnHeader Style="{StaticResource ColumnHeaderStyle}" Content="{x:Static codeCoverageNs:Resources.HierarchyColumnTitle}" Name="Hierarchy"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Tag="{Binding}" Margin="0,2,0,2">
<window:TreeListViewExpander/>
<Image Style="{StaticResource TreeEntryImageStyle}" />
<TextBlock Text="{Binding SummaryType, Converter={StaticResource EnumToStringConverter}}" Tag="{Binding}" VerticalAlignment="Center" Visibility="{Binding SummaryType, Converter={StaticResource SummaryBlockTypeVisibilityConverter}}" />
<TextBlock Text=":__ " Tag="{Binding}" VerticalAlignment="Center" Visibility="{Binding SummaryType, Converter={StaticResource SummaryBlockTypeVisibilityConverter}}"/>
<TextBlock Text="{Binding SummaryName}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</window:TreeListView.Columns>
</window:TreeListView>
它的风格如下:
<Style TargetType="{x:Type window:TreeListView}">
<!--Set the control template.-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type window:TreeListView}">
<ControlTemplate.Resources>
<!--Apply this style to all 'TreeViewItem's.-->
<Style TargetType="TreeViewItem" BasedOn="{StaticResource VSTreeViewItem}">
<Setter Property="Template" Value="{StaticResource TreeListViewItem}"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
<Setter Property="IsExpanded" Value="True"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static mfcolors:Environment.ToolWindowTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static mfcolors:Environment.ToolWindowBackgroundBrushKey}}" />
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static mfcolors:Environment.ToolWindowBackgroundBrushKey}}" />
<EventSetter Event="PreviewMouseDoubleClick" Handler="MainTree_OnPreviewItemDoubleClicked"/>
<EventSetter Event="KeyDown" Handler="MainTree_OnItemKeyDown"/>
<EventSetter Event="MouseRightButtonDown" Handler="MainTree_OnItemRightButtonDown"/>
</Style>
<!--Apply this style to all 'TreeListViewExpander's.-->
<Style TargetType="window:TreeListViewExpander">
<Setter Property="Template" Value="{StaticResource TreeListViewExpander}"/>
</Style>
</ControlTemplate.Resources>
<!--Create a standard border around the 'TreeListView'.-->
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<!--ScrollViewer providing horizontal scrolling functionality for both, content and headers.-->
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True">
<!--Grid containing the header row and all the content rows.-->
<Grid ScrollViewer.CanContentScroll="True">
<Grid.RowDefinitions>
<!--The header row.-->
<RowDefinition Height="Auto"/>
<!--The content row.-->
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--The header row.-->
<GridViewHeaderRowPresenter Columns="{TemplateBinding Columns}" AllowsColumnReorder="{TemplateBinding AllowsColumnReorder}">
</GridViewHeaderRowPresenter>
<!--ScrollViewer providing vertical scrolling functionality for the content.-->
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Grid.Row="1" ScrollViewer.CanContentScroll="True">
<!--ItemsPresenter containing the content.-->
<ItemsPresenter/>
</ScrollViewer>
</Grid>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
有人能发现我失踪的东西吗?例如,是否有必要将滚动条/网格包裹起来? 谢谢!