Esempio n. 1
0
        /// <summary>
        /// Returns true if TreeViewItem has children. DO NOT USE THIS PROPERTY DURING DRAG&DROP OPERATION
        /// </summary>
        public bool HasChildren(VirtualizingTreeView treeView)
        {
            if (treeView == null)
            {
                return(false);
            }
            int index = treeView.IndexOf(Item);

            TreeViewItemContainerData nextItem = (TreeViewItemContainerData)treeView.GetItemContainerData(index + 1);

            return(nextItem != null && nextItem.Parent == this);
        }
        /// <summary>
        /// Get First Child of TreeViewItem
        /// </summary>
        /// <returns>First Child</returns>
        public TreeViewItemContainerData FirstChild(VirtualizingTreeView treeView)
        {
            if (!HasChildren(treeView))
            {
                return(null);
            }

            int siblingIndex = treeView.IndexOf(Item);

            siblingIndex++;

            TreeViewItemContainerData child = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);

            Debug.Assert(child != null && child.Parent == this);

            return(child);
        }
        public TreeViewItemContainerData NextChild(
            VirtualizingTreeView treeView,
            TreeViewItemContainerData currentChild)
        {
            if (currentChild == null)
            {
                throw new ArgumentNullException(nameof(currentChild));
            }
            int siblingIndex = treeView.IndexOf(currentChild.Item) + 1;

            for (TreeViewItemContainerData itemContainerData = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex); itemContainerData != null && itemContainerData.IsDescendantOf(this); itemContainerData = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex))
            {
                if (itemContainerData.Parent == this)
                {
                    return(itemContainerData);
                }
                ++siblingIndex;
            }
            return((TreeViewItemContainerData)null);
        }
        /// <summary>
        /// Get Last Descendant Of TreeViewItem
        /// </summary>
        /// <returns>Last Descendant</returns>
        public TreeViewItemContainerData LastDescendant(VirtualizingTreeView treeView)
        {
            if (!HasChildren(treeView))
            {
                return(null);
            }

            int siblingIndex = treeView.IndexOf(Item);
            TreeViewItemContainerData lastDescendant = null;

            while (true)
            {
                siblingIndex++;
                TreeViewItemContainerData child = (TreeViewItemContainerData)treeView.GetItemContainerData(siblingIndex);

                if (child == null || !child.IsDescendantOf(this))
                {
                    return(lastDescendant);
                }

                lastDescendant = child;
            }
        }