Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase the spacing between TreeViewItems in a TreeView

Tags:

wpf

treeview

Im working with a TreeView in WPF. What I have is :-

TreeRoot -TreeViewItem1 -TreeViewItem2 -TreeViewItem3 -TreeViewItem4

What I want is

TreeRoot -TreeViewItem1

-TreeViewItem2

-TreeViewItem3

-TreeViewItem4

So, Is there a way to increase the spacing between the TreeViewItems

like image 931
gprasant Avatar asked Oct 26 '25 10:10

gprasant


1 Answers

If I understand the question correctly, you can modify the vertical spacing through the ItemContainerStyle property on the TreeView:

<Window.Resources>
    <Style x:Key="TreeViewItemStyle" TargetType="TreeViewItem">
        <Setter Property="Margin" Value="5 20 5 5" />
    </Style>
</Window.Resources>

<Grid>
    <TreeView ItemContainerStyle="{StaticResource TreeViewItemStyle}">
        <TreeViewItem Header="One" />
        <TreeViewItem Header="Two" />
        <TreeViewItem Header="Three" />
    </TreeView>
</Grid>
like image 51
Scott J Avatar answered Oct 29 '25 05:10

Scott J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!