views:

429

answers:

2

I have a corollary question to This one.

How can you change the spacing between the top of the TreeView Control and the first TreeViewItem? Specifically, I want to REDUCE the space between the top of the control and the first item. As with the other question, I'm guessing that I'll need go restyle the TreeView. But, what style do I need to chnage, and which property controls that particular space?

Thanks in advance.

+1  A: 

You can use the padding for the TreeView:

<TreeView Name="treeView1" Padding="0,50,0,0 ">
            <TreeViewItem Header="test" Selected="TreeViewItem_Selected">
                <TreeViewItem Header="sub test" />
            </TreeViewItem>
        </TreeView>

this will add a padding of 50 to the top of the inside of the treeview.

Jason Heine
Unfortunately, because I want to reduce the amount of space (I edited the question to reflect this) your option won't work. I tried padding, but that property won't accept negative numbers.
Steve Brouillard
Ahh, well, I tried :). I am glad you found your answer in another post.
Jason Heine
+1  A: 

I received the answer to my question on the Silverlight,net forums here. Essentially I needed to add a control template and change the margin on the ItemPresenter.

<ctl:TreeView>
  <ctl:TreeView.Template>
    <ControlTemplate TargetType="ctl:TreeView">
      <Grid x:Name="Root" >
        <Grid.Resources>
          <SolidColorBrush x:Key="BorderBrush" Color="#FF000000" />
        </Grid.Resources>
        <Border x:Name="Border" BorderBrush="{StaticResource BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
          <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" Margin="1">
            <ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="{x:Null}" BorderBrush="Transparent" BorderThickness="0" IsTabStop="False" TabNavigation="Once">
              <ItemsPresenter x:Name="TreeItems" Margin="5" />
            </ScrollViewer>
          </Border>
        </Border>
      </Grid>
    </ControlTemplate>
  </ctl:TreeView.Template>
<ctl:TreeView>
Steve Brouillard