locked
Treeview left margin

    Question

  • When I use a treeview control there is a big left margin on the whole control. I can't get rid of it and I've tried everything I can think of. You can notice the cap with the following example in XAML.

        <Grid x:Name="LayoutRoot" Background="Lime">
    <controls:TreeView HorizontalAlignment="Left" VerticalAlignment="Top">
    <controls:TreeViewItem Header="Test 1" />
    <controls:TreeViewItem Header="Test 2" />
    <controls:TreeViewItem Header="Test 3" />
    <controls:TreeViewItem Header="Test 4" />
    </controls:TreeView>
    </Grid>
     
    Monday, July 6, 2009 3:01 AM

Answers

  • Use Expression Blend. May be this can help you:

    <Grid x:Name="LayoutRoot" Background="Lime">
            <controls:TreeView HorizontalAlignment="Left" VerticalAlignment="Top">
                <controls:TreeViewItem Header="Test 1" Width="55" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0" />
                <controls:TreeViewItem Header="Test 2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0"  />
                <controls:TreeViewItem Header="Test 3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0"  />
                <controls:TreeViewItem Header="Test 4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0" />
            </controls:TreeView>
        </Grid>

    HTH Smile

    Monday, July 6, 2009 3:15 AM
  • That space is there for the expander-buttons. If you add a child to one of the root items, you will see why that space is taken. If that margin wasn't there, you wouldn't be able to expand the nodes. What are you trying to achieve? You could override the treeviewitem-template and set the margin (and maybe collapse the togglebutton?) but you might be better off using a listbox?
    Monday, July 6, 2009 3:21 AM

All replies

  • Use Expression Blend. May be this can help you:

    <Grid x:Name="LayoutRoot" Background="Lime">
            <controls:TreeView HorizontalAlignment="Left" VerticalAlignment="Top">
                <controls:TreeViewItem Header="Test 1" Width="55" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0" />
                <controls:TreeViewItem Header="Test 2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0"  />
                <controls:TreeViewItem Header="Test 3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0"  />
                <controls:TreeViewItem Header="Test 4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-20,0,0,0" />
            </controls:TreeView>
        </Grid>

    HTH Smile

    Monday, July 6, 2009 3:15 AM
  • That space is there for the expander-buttons. If you add a child to one of the root items, you will see why that space is taken. If that margin wasn't there, you wouldn't be able to expand the nodes. What are you trying to achieve? You could override the treeviewitem-template and set the margin (and maybe collapse the togglebutton?) but you might be better off using a listbox?
    Monday, July 6, 2009 3:21 AM
  • Well of course it is! Seemed a bit odd without having any expanders on my treeview. I'm actually going to have some in the end so there's no problem at all. Maybe varshavmane's solution also work but I don't want that now that I remember the expanders :) Somehow I thought the treeview would change based if there are expanders or not. Thanks both of you anyway.

    Monday, July 6, 2009 3:34 AM