0
votes

I have a 4 row, 1 column Grid wrapped in a ScrollViewer. The rows are Treeviews that are bound to hierarchy (nested Lists) of objects. I'm using a HierarchicalDataTemplate to lay out the TreeViewItem nodes and their children / ItemTemplates.

My problems is that whenever I expand the TreeViewItems, the vertical scrollbar is not showing up. Oddly enough, the horizontal scrollbar will show up when I expand out an AccordionItem that is part of the child nodes.

I have tried creating an event handler that calls UpdateLayout() whenever a TreeViewItem is expanded, but that's not causing the scrollbar to appear. I have tried calling UpdateLayout() against the TreeView, the Grid, and the ScrollViewer as well.

2

2 Answers

0
votes

The answer to this became painfully obvious after some experimentation.

Specifying the Height property for the ScrollViewer was the missing piece that made everything work as it would be expected.

<ScrollViewer HorizontalScrollBarVisibility="Auto" 
              VerticalScrollBarVisibility="Auto" 
              Height="350">  <!-- THIS was the missing piece!! -->
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Controls:TreeView Grid.Row="0" ItemsSource="{Binding ListOne}" 
       ItemTemplate="{StaticResource ListOneTemplate}" >
    </Controls:TreeView>

    <Controls:TreeView Grid.Row="1" ItemsSource="{Binding ListTwo}" 
       ItemTemplate="{StaticResource ListTwoTemplate}" >
    </Controls:TreeView>

  </Grid>
</ScrollViewer>

FWIW, I tried a number of other solutions including setting heights and maxheights for the Grid, GridRows, and TreeView. I also tried creating an event to set the height of the scrollviewer whenever the grid height changed, and an event that fired off cascading UpdateLayouts() whenever a tree view item changed.

Setting the height on the ScrollViewer was the only approach I found that made everything work as expected.

0
votes

Also, you can set the row definition:

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/> // tree view position
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

The treeview will take the free space of the screen, showing scrollbars if necessary.