1

so I have a TreeView control in my XAML. It works fine. If I extend the treeview to be larger than the user control it resides in, I get a scroll bar, which is good. However, inside this user control I want some other things. So I put the treeview in a stack panel with some other things, and this time I don't get the scroll bar if the treeview expands to be larger than the user control it's in.

Is this something other people have come across, and is there a fix for it?

2 Answers2

2

Embed your stackpanel inside a ScrollViewer: stackoverflow.com/a/6250287/7517676. You also might have to explicitly set VerticalScrollBarVisibility and HorizontalScrollBarVisibility, depending on your need. Here's a code sample:

<ScrollViewer VerticalScrollBarVisibility="Auto">
  <StackPanel ... />
</ScrollViewer>
AnujGeek
  • 130
  • 1
  • 8
0

Based on this answer a StackPanel isn't the right container for a TreeView, but a Grid is. So this will enable scrolling inside the TreeView, by mouse and scrollbar:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="30"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Label>Some descriptive label.</Label>
    <TreeView Grid.Row="1" ItemsSource="{Binding SomeSource, Mode=OneWay}">
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate DataType="{x:Type local:MyNodeType}" ItemsSource="{Binding Children}">
                <Label Content="{Binding NodeName}"/>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>
</Grid>
Hans Kesting
  • 38,117
  • 9
  • 79
  • 111