private void OnItemSelected(object sender, RoutedEventArgs e) { TreeViewItem source = e.OriginalSource as TreeViewItem; MainWindow mainWindow = System.Windows.Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); try { CustomDrive sourceItem = (CustomDrive)source.Header; mainWindow.ctrChildView.Custom.Items.Clear(); foreach (var item in sourceItem.Items) { mainWindow.ctrChildView.Custom.Items.Add(item); } } catch (InvalidCastException) { try { CustomDirectory sourceItem = (CustomDirectory)source.Header; CustomItemController = new CustomItemController() { CustomDirectory = sourceItem }; var files = CustomItemController.GetCustomFiles(sourceItem.Name); mainWindow.ctrChildView.Custom.Items.Clear(); foreach (var item in sourceItem.Items) { mainWindow.ctrChildView.Custom.Items.Add(item); } foreach (var file in files) { mainWindow.ctrChildView.Custom.Items.Add(file); } } catch (InvalidCastException) { } } }
private void OnExpanded(object sender, RoutedEventArgs e) { TreeViewItem source = e.OriginalSource as TreeViewItem; try { CustomDrive sourceItem = (CustomDrive)source.Header; foreach (CustomDirectory dir in sourceItem.Items) { dir.ShortName = dir.Name.Remove(0, dir.Name.LastIndexOf("\\") + 1); CustomItemController = new CustomItemController() { CustomDirectory = dir }; CustomItemController.GetCustomDirectories(dir.Name); } } catch (InvalidCastException) { try { CustomDirectory sourceItem = (CustomDirectory)source.Header; foreach (var dir in sourceItem.Items) { if (dir.Type.Equals("File folder")) { CustomItemController = new CustomItemController() { CustomDirectory = (CustomDirectory)dir }; CustomItemController.GetCustomDirectories(dir.Name); } } } catch (InvalidCastException) { } } }