Alex Rivera | Logout

Enable scroll for WPF Treeview

Asked 2009-08-21T09:34:30.743
32

Can anybody help me out with how to enable a treeview to scroll? There must be a simple way but I can't make it work in my code. After multiple failed tries, I currently have something like this:

        <ScrollViewer CanContentScroll="True">
           <TreeView ...>
           </TreeView>
        </ScrollViewer>

I do see an 'disabled' scrollbar, but when the notes of the treeview are larger than the screen height, no scrolling is activated.

Edit
Report

1 Answer

10

The TreeView contains a ScrollViewer, but as @Carlo said, the TreeView or its container needs to have a height. Alternatively, the TreeView should be hosted in a container that doesn't give infinite height to its children (i.e. a StackPanel which I think was what @Kent was meaning). So place it inside a Grid, no need to give the Grid or the TreeView an explicit height and you should get the scrollbars.

answered 2010-07-20T16:20:25.677

Your Answer