I am trying to build a three level treeview in WPF. Basically, I have a list of top level items that all have one more child items. Those child item may or may not have themselves chid items.
Anyone know of a tutorial available on the net?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The simplest way is to use bindings and
HierarchicalDataTemplate. Declare a class with your data :And define a
HierarchicalDataTemplatefor this type :Now you just need to bind the
ItemsSourceof theTreeViewto your collection of top-level items, and the tree nodes will be constructed automatically. If you need to add (or remove) a node, just add an item to (or remove it from) the parent collectionFor this example, I used a single item type, but if you have several types to display in the
TreeViewyou will need to define aHierarchicalDataTemplatefor each. For leaf nodes (nodes with no children), you can just use a regularDataTemplate