コード例 #1
0
        private void ReplaceElement(TreeViewItemLabeled oldElement, TreeViewItemLabeled newElement)
        {
            var originalParentIndex = _folderStructure.IndexOf(oldElement);

            _folderStructure.RemoveAt(originalParentIndex);
            _folderStructure.Insert(originalParentIndex, newElement);
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        //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;
        }