private void CreateRoot(string rootPath) { root = new FolderNode() { FolderDirectory = rootPath }; GetChildNode(root); dir = new ObservableCollection <FolderNode>(); dir.Add(root); treeDirectory.ItemsSource = dir; }
private void GetChildNode(FolderNode parent, string currentPath = "") { try { foreach (string folder in Directory.EnumerateDirectories(parent.FolderDirectory)) { FolderNode folderNode = new FolderNode() { FolderDirectory = folder }; parent.ChildFolders.Add(folderNode); } foreach (string file in Directory.EnumerateFiles(parent.FolderDirectory)) { FolderNode folderNode = new FolderNode() { FolderDirectory = file }; folderNode.Type = NodeType.File; parent.ChildFolders.Add(folderNode); } } catch { } }
private void treeDirectory_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { FolderNode currentNode = (treeDirectory.SelectedItem as FolderNode); GetChildNode(currentNode); }