Silverlight - Space above / below TreeView controls

I am trying to reduce the amount of space between TreeViews to be more vertically. I am guessing it is a matter of styling the ItemContainer Style or ItemContainer template in the TreeView, but I cannot get the correct properties. Can anyone point me in the right direction?

0


a source to share


1 answer


You are correct, you need to change the ItemContainerStyle of the TreeView control.

All containers in the TreeViewItem template control are set to "auto" by default and stretch to consume as much vertical space as needed for the item's content.

You can force this to do one of two things:



  • Reduce the size of the content of each item by changing the TreeView ItemTemplate
  • Invert the marker in the grid inside the default TreeViewItem control template.

Below is a snippet of a new control template I created for the TreeViewItem. Notice how I set the margin to "0, -4.0, -4". This says the content should be 4 pixels at the top and bottom of the element, thereby reducing the vertical real estate of each element.

<ControlTemplate TargetType="controls:TreeViewItem">
    <Grid Background="{x:Null}" Margin="0,-4,0,-4">
        ...

      

+2


a source







All Articles