When I make a list box in WPF I frequently set its ItemsSource to be a List. Is there a Tree for TreeView (or what goes in ItemsSource for TreeView)?
Is there a collection or generally accepted method for handling tree data in C#.NET?
In the C# language a tree can be implemented with classes (nodes) that point to further nodes. In this simple implementation, we use a Dictionary. AddWord This method takes a string argument and adds it to the tree by creating (or using existing) nodes (one per character).
What you want to do is bind a collection of hierarchical objects to the tree view using the Hierarchical Data Template.
I have written a blog post on this very subject, check it out,
Displaying Hierarchical Data with the WPF Tree View control
Nothing built in as far as I know. What I usually do is something like this:
class User
{
string Name { get; set; }
List<User> { get; set; }
}
Then you can use that to bind to your hierarchical control, such as a TreeView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With