0

I am trying to show multiple types in the tree view

I have Projects, which contain workspaces

Here is the image

When Projects are expanded can see list of workspaces.

I have tried using <TreeViewItem Header="My Projects" ItemSource="{Binding Projects}"> but "My Projects" is becoming a root node and Project1, Project2... becomes its child nodes.

Also I have tried a Label with "My Projects" inside the treeview but could get to show as needed.

So Finally I ended up with a tree view for Projects and Followed by another tree view for Workspaces.

Is it possible to implement this in a single tree view?

user3013076
  • 515
  • 1
  • 7
  • 15
  • I think fallow like solution is so good [WPF Treeview Databinding Hierarchal Data with mixed types][question]. [question]:http://stackoverflow.com/questions/3673173/wpf-treeview-databinding-hierarchal-data-with-mixed-types/3673232#3673232 – ebadola sobhanwerdy Nov 26 '14 at 23:44

1 Answers1

0

Try adding different HierarchicalDataTemplates for Project type and Workspace type separately instead of directly creating TreeViewItems inside:

<TreeView ItemsSource="{Binding Projects}">
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="model:Project (Whatever type you are using for Project)" ItemsSource="{Binding Workspaces}">
            <TextBlock Text="{Binding Name}" />
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="model:Workspace (Whatever type you are using for Workspace)">
            <TextBlock Text="{Binding Name}" />
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>
nakiya
  • 14,063
  • 21
  • 79
  • 118
  • See the problem here is adding section/group names "My Projects" and "My Workspaces". Not showing the Hierarchical data. – user3013076 Sep 15 '14 at 05:53