// Used to expand current folder by one layer: load all items under this folder public static void FolderGenerator(TreeFolderInfo currentFolder) { // Clear temp currentFolder.Folders.Clear(); // Add items to folder try { foreach (DirectoryInfo subInfo in currentFolder.Info.EnumerateDirectories()) { // Generate Folders TreeFolderInfo subFolder = new TreeFolderInfo(null, subInfo); subFolder.bSelected = currentFolder.bSelected; // Let Children share the same status of selection as parent subFolder.Folders.Add(new TreeFolderInfo(true)); currentFolder.Folders.Add(subFolder); } } catch (UnauthorizedAccessException) { } catch (PathTooLongException) { } try { foreach (FileInfo file in currentFolder.Info.EnumerateFiles()) { // Generate Files TreeFileInfo fileInfo = new TreeFileInfo(file); fileInfo.bSelected = currentFolder.bSelected; currentFolder.Files.Add(fileInfo); } } catch (UnauthorizedAccessException) { } catch (System.IO.PathTooLongException) { } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { TreeFolderInfo input = value as TreeFolderInfo; CompositeCollection collection = new CompositeCollection(); collection.Add(new CollectionContainer() { Collection = input.Folders }); collection.Add(new CollectionContainer() { Collection = input.Files }); return(collection); }