// Using convention and reflection to get RootItem iRootNr //If iRootNr>= ListNavTreeRootItemsByConvention().Count we use driveItem by default public static NavTreeItem ReturnRootItem(int iRootNr, bool includeFileChildren = false) { // Set default System.Type Type selectedType = typeof(DriveRootItem); string selectedName = "Drive"; // Can you find other type given the conventions ..RootItem name and iRootNr var entityTypes = from t in System.Reflection.Assembly.GetAssembly(typeof(NavTreeItem)).GetTypes() where t.IsSubclassOf(typeof(NavTreeItem)) select t; int i = 0; foreach (var tt in entityTypes) { if (tt.Name.EndsWith(LastPartRootItemName)) { if (i == iRootNr) { selectedType = Type.GetType(tt.FullName); selectedName = tt.Name.Replace(LastPartRootItemName, ""); break; } i++; } } // Use selectedType to create root .. NavTreeItem rootItem = (NavTreeItem)Activator.CreateInstance(selectedType); rootItem.FriendlyName = selectedName; rootItem.IncludeFileChildren = includeFileChildren; return(rootItem); }
// Constructors public DirectoryPickerViewModel(int pRootNumber = 0, bool pIncludeFileChildren = false) { try { CheckSelectedPath(Properties.Settings.Default.Zenfolio7_SelectedPath); } catch (Exception ex) { //do something } SelectedPathFromTreeCommand = new RelayCommand(SelectedPathFromTree); RootChildren = new ObservableCollection <INavTreeItem> { }; // create a new RootItem given rootNumber using convention RootNr = pRootNumber; NavTreeItem treeRootItem = NavTreeRootItemUtils.ReturnRootItem(pRootNumber, pIncludeFileChildren); TreeName = treeRootItem.FriendlyName; // Delete RootChildren and init RootChildren ussing treeRootItem.Children foreach (INavTreeItem item in RootChildren) { item.DeleteChildren(); } RootChildren.Clear(); foreach (INavTreeItem item in treeRootItem.Children) { RootChildren.Add(item); } }
public void RebuildTree(int pRootNr = -1, bool pIncludeFileChildren = false) { // First take snapshot of current expanded items List <String> SnapShot = NavTreeUtils.TakeSnapshot(rootChildren); // As a matter of fact we delete and construct the tree//RoorChildren again..... // Delete all rootChildren foreach (INavTreeItem item in rootChildren) { item.DeleteChildren(); } rootChildren.Clear(); // Create treeRootItem if (pRootNr != -1) { RootNr = pRootNr; } treeRootItem = NavTreeRootItemUtils.ReturnRootItem(RootNr, pIncludeFileChildren); if (pRootNr != -1) { TreeName = treeRootItem.FriendlyName; } // Copy children treeRootItem to RootChildren, set up new tree foreach (INavTreeItem item in treeRootItem.Children) { RootChildren.Add(item); } //Expand previous snapshot NavTreeUtils.ExpandSnapShotItems(SnapShot, treeRootItem); }
// Constructors public NavTreeVm(int pRootNumber = 0, bool pIncludeFileChildren = true) { // create a new RootItem given rootNumber using convention RootNr = pRootNumber; treeRootItem = NavTreeRootItemUtils.ReturnRootItem(pRootNumber, pIncludeFileChildren); TreeName = treeRootItem.FriendlyName; //treeRootItem.IsExpanded // Delete RootChildren and init RootChildren using treeRootItem.Children foreach (INavTreeItem item in RootChildren) { item.DeleteChildren(); } RootChildren.Clear(); foreach (INavTreeItem item in treeRootItem.Children) { RootChildren.Add(item); } selectedPathFromTreeCommand = new DelegateCommand(LoadImagesToListbox); }
// Constructors public NavTreeVm(int pRootNumber = 0, bool pIncludeFileChildren = false) { // create a new RootItem given rootNumber using convention RootNr = pRootNumber; NavTreeItem treeRootItem = NavTreeRootItemUtils.ReturnRootItem(pRootNumber, pIncludeFileChildren); TreeName = treeRootItem.FriendlyName; // Delete RootChildren and init RootChildren ussing treeRootItem.Children foreach (INavTreeItem item in RootChildren) { item.DeleteChildren(); } RootChildren.Clear(); foreach (INavTreeItem item in treeRootItem.Children) { RootChildren.Add(item); } }