WPF TreeView with horizontal orientation?

前端 未结 2 750
眼角桃花
眼角桃花 2020-12-18 13:11

What would be the bast way to change the orientation of the WPF treeview. I would like to work the expand-collapse-functionality to work left to right instead of top to down

2条回答
  •  粉色の甜心
    2020-12-18 13:41

    To expand on John Smith's CodeProject article, if you want to have horizontal layout on only a particular level in the tree (instead of on all levels like his article shows), then just set the ItemsPanel property on the TreeViewItem at the level you want to have a StackPanel.

    It wasn't intuitive to me at first, but you can get to this property through the ItemContainerStyle property of the HierarchicalDataTemplate for the layer above the layer you want to be horizontal.

    Like this:

    
        
    
    
    
        
            
        
        
    
    

    Following this pattern will let you set horizontal layout for any individual layer within your tree, except the root layer. And if you want the root layer to be horizontal, then just set the ItemsPanel property on the TreeView to use a horizontal StackPanel.

提交回复
热议问题