5
votes

I need a control that behaves like a treeview (binds to a tree structure, expands child nodes based on IsExpanded property of bound object), yet displays data like the grid (no indenting, or toggle images).

The expand collapse will be happening automatically based on bound object.

TreeView is perfect, i just need to remove the indentation and the triangle image to make it vertically flat, like a grid column.

I suppose i could try overriding the TreeViewItem template, but that just doesn't display anything..

2

2 Answers

2
votes

Based on the TreeView style on MSDN, something like this should work:

<Style TargetType="TreeViewItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TreeViewItem">
                <StackPanel>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="ExpansionStates">
                            <VisualState x:Name="Expanded">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetProperty="(UIElement.Visibility)"
                                        Storyboard.TargetName="ItemsHost">
                                        <DiscreteObjectKeyFrame KeyTime="0"
                                            Value="{x:Static Visibility.Visible}" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Collapsed" />
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <ContentPresenter ContentSource="Header" />
                    <ItemsPresenter Name="ItemsHost" Visibility="Collapsed" />
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
2
votes

You need a TreeListView (it combines the TreeView and ListView at TreeViewItem template level beautifully)

http://msdn.microsoft.com/en-us/library/ms771523.aspx