![]() ![]() That's enough to get us the drive/folder hierarchy for the TreeView. Subitem.Expanded += new RoutedEventHandler(folder_Expanded) Subitem.Header = s.Substring(s.LastIndexOf( " \\") + 1) TreeViewItem subitem = new TreeViewItem() If ( = 1 & item.Items = dummyNode)įoreach ( string s in Directory.GetDirectories(())) TreeViewItem item = (TreeViewItem)sender Void folder_Expanded( object sender, RoutedEventArgs e) Item.Expanded += new RoutedEventHandler(folder_Expanded) Private void Window_Loaded( object sender, RoutedEventArgs e)įoreach ( string s in Directory.GetLogicalDrives()) The first step is to get it to display the correct tree, which is really down to the following two methods. So How did I Get the WPF TreeView to do that So that's what this article is all about. I think it's probably going to be a fairly common requirement to display different images for the current TreeViewItem based on some condition. So I thought that as the big article where this technique is used is still being written, I would break out the tree view implementation into a smaller article (this one). Wrong, it turned out to be quite tricky, well at least it was for me. I wanted to display a drive image if the TreeViewItem is a drive, and a folder image otherwise. I am still getting to grips with WPF, and last night, as part of a larger article that I am still working on, I wanted to create a simple (basic version) of an explorer tree, which shows drives and folders. Download demo application (includes source code) - 115.7 KB. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |