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)?
开发者_C百科Is there a collection or generally accepted method for handling tree data in C#.NET?
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.
It is certainly possible to data bind a source to a WPF TreeView
instance. Here are a couple of blogs and sample entries on the subject
- http://blogs.msdn.com/chkoenig/archive/2008/05/24/hierarchical-databinding-in-wpf.aspx
- http://msdn.microsoft.com/en-us/library/aa972151.aspx
There is an open source project that was originally by Wintellect, found here, called PowerCollections. Maybe there is something there that might help you?
Hope this helps, Best regards, Tom.
You might want to look at binding XML via XLinq to your treeview, such as here: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/02a47e46-12e9-45fb-af18-4511f2212acb/ and here: http://www.beacosta.com/blog/?p=50.
精彩评论