Search code examples
wpftreeviewtreeviewitem

WPF TreeView question


Is it possible to store some data in every item of a TreeView control? I mean, something useful (e.g. a string) besides the header text? Thanks.


Solution

  • It depends on what you mean by store data...

    If you're just talking UI customization Rachel's answer above works.

    If you're talking about storing arbitrary object values, such as information about the TreeViewItem, or maybe a relation between two items, you can use the Tag property of TreeViewItem. For example, I had to write a mapping UI where two trees linked together where each TreeViewItem from the first tree, could connect to 1 TreeViewItems of the second tree. I used the Tag property of the first TreeViewItem to store the connecting TreeViewItem.