Showing posts with label HierarchicalDataTemplate. Show all posts
Showing posts with label HierarchicalDataTemplate. Show all posts

Thursday 11 April 2013

WPF - Different Data Templates for Different Child Types in a TreeView

The TreeView control in WPF allows us to display hierarchical data and allows us to customise the appearance of this by setting the ItemTemplate property using a HierarchicalDataTemplate, giving us expandable nodes within our tree. However, we can only set the ItemTemplate property once with one data template. Imagine the scenario where you want to display a directory structure. A directory can contain files or other directories which in turn can also contain files or other directories and so on. You might want to use a different data template for files than for directories but as stated earlier you can only set the ItemTemplate property once, so how can we achieve this?