Click here to Skip to main content
15,888,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created a MultiSelection Tree view, which supports virtualization. When I try to expand it and add columns, virtualization stops working.

Can anyone spot what I'm missing? Is it necessary to wrap the scroller/grids by other elements, for instance? Thanks!

The working tree's xaml is pretty simple - no styling (except to have all items expanded) I placed the new tree (which has columns) alongside the old one (same main grid). It is formatted like this:
XML
<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>


and its style looks like this:
XML
<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 removed="{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>


What I have tried:

Using Snoop, and relying on previous posts, I tried setting VirtualizingStackPanel.IsVirtualizing="True" and ScrollViewer.CanContentScroll="True" on the tree and scrollers. No good...
Posted
Updated 6-Mar-16 0:08am
v2
Comments
Kornfeld Eliyahu Peter 6-Mar-16 7:47am    
Any error?
J. Calhoun 8-Mar-16 12:04pm    
There was a similar issue that someone had where an unnamed style, or a style without a key, that was conflicting with the treeview. Could this be your issue? The description of the issue could be found here[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900