private void ReplaceElement(TreeViewItemLabeled oldElement, TreeViewItemLabeled newElement) { var originalParentIndex = _folderStructure.IndexOf(oldElement); _folderStructure.RemoveAt(originalParentIndex); _folderStructure.Insert(originalParentIndex, newElement); }
private IEnumerable <TreeViewItemLabeled> GetAvalibleDrives() { var allDrives = DriveInfo.GetDrives(); foreach (var driveInfo in allDrives) { if (driveInfo.IsReady && (ShouldShowNonFixedDrives || driveInfo.DriveType == DriveType.Fixed)) { TreeViewItemLabeled item; try { item = new TreeViewItemLabeled { Header = string.Join(" ", driveInfo.Name, driveInfo.VolumeLabel), Tag = driveInfo.Name, IconSource = NativeMethods.GetLargeIcon(driveInfo.Name) }; } catch (Exception) { continue; } yield return(item); } } }
private void ReplaceAllTopLevelElements(TreeViewItemLabeled childElement, FrameworkElement originalSender) { var parent = originalSender.Parent as TreeViewItemLabeled; if (parent == null) { return; } var elementIndex = parent.Items.IndexOf(originalSender); var originalParent = new TreeViewItemLabeled(); while (parent != null) { originalParent = parent; parent.Items.RemoveAt(elementIndex); parent.Items.Insert(elementIndex, childElement); childElement = parent; parent = childElement.Parent as TreeViewItemLabeled; if (parent != null) { elementIndex = parent.Items.IndexOf(originalParent); } } ReplaceElement(originalParent, childElement); }
//Hack! /// <summary> /// Here we reset element content by raising Expanded/Collapsed event which causes element to reload it's contents /// </summary> /// <param name="element">Element to reset</param> private static void ResetElementContent(TreeViewItemLabeled element) { element.IsExpanded = false; element.IsExpanded = true; }