コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TreeItemContainerGenerator{T}"/> class.
        /// </summary>
        /// <param name="owner">The owner control.</param>
        /// <param name="contentProperty">The container's Content property.</param>
        /// <param name="itemsProperty">The container's Items property.</param>
        /// <param name="isExpandedProperty">The container's IsExpanded property.</param>
        /// <param name="rootGenerator">
        /// The item container for the root of the tree, or null if this generator is itself the
        /// root of the tree.
        /// </param>
        public TreeItemContainerGenerator(
            IControl owner,
            PerspexProperty contentProperty,
            PerspexProperty itemsProperty,
            PerspexProperty isExpandedProperty,
            ITreeItemContainerGenerator rootGenerator)
            : base(owner, contentProperty)
        {
            ItemsProperty      = itemsProperty;
            IsExpandedProperty = isExpandedProperty;
            RootGenerator      = rootGenerator;

            if (rootGenerator == null)
            {
                _itemToContainer = new Dictionary <object, T>();
                _containerToItem = new Dictionary <IControl, object>();
            }
        }
コード例 #2
0
        public void Update(TreeView treeView, ITreeItemContainerGenerator itemContainerGenerator, IDropInfo dropInfo)
        {
            int indexOfDrop = dropInfo.InsertIndex;
            var container   = itemContainerGenerator.ContainerFromIndex(indexOfDrop);

            if (container == null)
            {
                if (indexOfDrop == 0)
                {
                    drawRect = new Rect(0, 0, treeView.Width, 1);
                }
                else
                {
                    container = itemContainerGenerator.ContainerFromIndex(indexOfDrop - 1);
                    if (container != null)
                    {
                        drawRect = new Rect(container.Bounds.X, container.Bounds.Bottom, container.Bounds.Width, 1);
                    }
                    else
                    {
                        drawRect = new Rect(0, 0, 0, 1);
                    }
                }
            }
            else
            {
                double  y      = 0;
                IVisual parent = container.VisualParent;
                while (parent != null && parent != treeView)
                {
                    y     += parent.Bounds.Y;
                    parent = parent.VisualParent;
                }

                var header = container.GetVisualChildren().FirstOrDefault().GetVisualChildren().FirstOrDefault();
                var height = header?.Bounds.Height ?? container.Bounds.Height;

                double top    = container.TranslatePoint(new Point(0, 0), treeView)?.Y ?? 0;
                double bottom = container.TranslatePoint(new Point(0, height), treeView)?.Y ?? 0;

                if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) &&
                    dropInfo.DropTargetAdorner == DropTargetAdorners.Highlight)
                {
                    drawRect = new Rect(container.Bounds.X + 1, top, container.Bounds.Width - 2, container.Bounds.Height);
                }
                else if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.BeforeTargetItem))
                {
                    drawRect = new Rect(container.Bounds.X, top, container.Bounds.Width, 1);
                }
                else
                {
                    drawRect = new Rect(container.Bounds.X, bottom, container.Bounds.Width, 1);
                }
            }

            /*var scroll = treeView.FindDescendantOfType<ScrollViewer>();
             * if (scroll != null)
             *  drawRect = new Rect(drawRect.X, drawRect.Y - scroll.Offset.Y, drawRect.Width, drawRect.Height);
             */
            InvalidateVisual();
        }