0

I got the following xaml code (simplified) :

        <StackPanel Grid.Row="2">
            <TreeView x:Name="a" VerticalAlignment="Stretch" BorderThickness="0">
            [...]
            </TreeView>

            <TreeView Name="b" VerticalAlignment="Stretch" BorderThickness="0">
            [...]
            </TreeView>
        </StackPanel>

My StackPanel is contained in a Grid in a certain Column and in Row 2. The thing is that when one of my TreeView is being too "long" (vertically), I haven't a ScrollBar that appears...

I tried to add the property

CanVerticallyScroll="True"

to the StackPanel but it doesn't change anything...

Any help ?

Guillaume Slashy
  • 3,554
  • 8
  • 43
  • 68
  • 1
    try this one .... – punker76 Nov 22 '11 at 10:40
  • 1
    See http://stackoverflow.com/questions/1310966/enable-scroll-for-wpf-treeview – SvenG Nov 22 '11 at 10:45
  • @punker76 : This seems to work and in fact it doesn't. I mean this code (yours) just give me the opportuny to get a 2 steps Scrollbar. If my 1st TreeView has 100 elements, I just can see the 15th first elements and when I "scroll down", I directly go to the 2nd TreeView. – Guillaume Slashy Nov 22 '11 at 11:47
  • @SvenG : Some guys talk about the incompatibily between StackPanel and ScrollViewer but as far as I know I HAVE to use a StackPanel (2 TreeViews in the same "zone/area"). What can I do ? – Guillaume Slashy Nov 22 '11 at 11:49
  • Don't use the Scrollviewer inside the StackPanel, rather use an additional Scrollviewer around the StackPanel – SvenG Nov 22 '11 at 12:39
  • This doesn't work. StackPanel tell to its children that they have an infinite space so they don't feel the need of a ScrollBar :( – Guillaume Slashy Nov 22 '11 at 12:48
  • Are you sure you don't have another issue in your XAML? my above snippet in a demo project produces a perfect Scrollviewer, that is only visible when you have too many items that don't fit on the screen.. – SvenG Nov 22 '11 at 13:05

1 Answers1

0

if you want in both treeviews scrollbars you can do this:

<Grid Height="100" Width="500">
  <Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition />
  </Grid.RowDefinitions>

  <TreeView Grid.Row="0">
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
  </TreeView>
  <TreeView Grid.Row="1">
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
    <TreeViewItem>Test</TreeViewItem>
  </TreeView>
</Grid>

I think this variant with StackPanel is not a good solution.

<Grid Height="100" Width="500">
  <StackPanel>

    <TreeView Grid.Row="0" MaxHeight="50">
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
    </TreeView>
    <TreeView Grid.Row="1" MaxHeight="50">
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
      <TreeViewItem>Test</TreeViewItem>
    </TreeView>

  </StackPanel>
</Grid>
punker76
  • 14,326
  • 5
  • 58
  • 96
  • yep I'd like to but I can't. My grid is divided in different rows/columns and my 2 TreeViews have to be in the same [row, column] box :( – Guillaume Slashy Nov 22 '11 at 12:24
  • Without a StackPanel I can't definie my 2 TreeViews in the same row/column area :/ As far as I understand how Grid.RowSpan/ColumnSpan works, I still can't define 2 TreeViews without StackPanels – Guillaume Slashy Nov 22 '11 at 12:51
  • ok, please post more source code, about the basic structure of the xaml code. – punker76 Nov 22 '11 at 13:21
  • I don't speak german :( Anyway, I fixed the problem with a DockPanel instead of a StackPanel and addesd the property "DockPanel.Dock="Top"" to my 2 TreeViews, I give you the acceptance for your help ;) – Guillaume Slashy Nov 22 '11 at 13:23