0

Basically i have a eeview that has a bunch of objects in it and the treeview needs to bind the same properties.

here is the code im using and it doesnt seem to work

    <TreeView ItemsSource="{Binding Drives}">
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate>
                <TreeViewItem Header="{Binding Name}" ItemsSource="{Binding Folders}" IsExpanded="{Binding IsExpanded, Mode=TwoWay}">
                    <TreeViewItem.ItemTemplate>
                        <HierarchicalDataTemplate>
                            <StackPanel>
                                <TreeViewItem Header="{Binding Name}" ItemsSource="{Binding Folders}" IsExpanded="{Binding IsExpanded,Mode=TwoWay}">
                                    <TreeViewItem.ItemTemplate>
                                        <HierarchicalDataTemplate>
                                            <TreeViewItem Header="{Binding Name}" ItemsSource="{Binding Folders}" IsExpanded="{Binding IsExpanded,Mode=TwoWay}"/>
                                        </HierarchicalDataTemplate>
                                    </TreeViewItem.ItemTemplate>
                                </TreeViewItem>
                            </StackPanel>
                        </HierarchicalDataTemplate>
                    </TreeViewItem.ItemTemplate>
                </TreeViewItem>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>

Basically when i get to the third level of treeview items i just get the Namespace+ObjectName. Isnt the DataTemplate supposed to flow on and on ?

New Bee
  • 991
  • 1
  • 13
  • 24
  • have you tried to remove the stackpanel? – sexta13 Sep 10 '14 at 23:53
  • 1
    You don't need to nest `HierarchicalDataTemplate`s like this. A single one would do assuming that the `ItemsSource` is `Folders` in each item in the `TreeView`. Further, check the output window for any binding errors. – nakiya Sep 11 '14 at 00:59
  • Im getting no binding errors. the binds are all working however the templates are not – New Bee Sep 11 '14 at 02:11
  • Please post your view model code. – nakiya Sep 11 '14 at 02:21

1 Answers1

1

More like this

    <TreeView ItemsSource="{Binding Drives}">
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Folders}">
                <TextBlock Text="{Binding Name}"></TextBlock>
                <HierarchicalDataTemplate.ItemContainerStyle>
                    <Style TargetType="TreeViewItem">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}" />
                    </Style>
                </HierarchicalDataTemplate.ItemContainerStyle>
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>
  • using this code i get one level of the treeview templated (Base level) and no others each treeview item in the tree needs to be binded to the property Folders – New Bee Sep 11 '14 at 02:28
  • Interesting because I get all levels. Do you want me to send you the whole repo code? – dharshana jagoda Sep 11 '14 at 08:20