Пример #1
0
        private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!_treeView.HasItems || e.OriginalSource.GetType().Name == "TextBoxView")
            {
                return;
            }

            _mouseDownPos = e.GetPosition(_treeView);

            var result = VisualTreeHelper.HitTest(_treeView, _mouseDownPos.Value);

            if (result == null)
            {
                return;
            }

            var treeViewItem = TreeUtil.FindVisualParent <TItem>(result.VisualHit);

            if (treeViewItem == null)
            {
                return;
            }

            Init(treeViewItem, e);
        }
Пример #2
0
        private TItem GetOverlapItem(TContainer rootTreeView, Point draggingPoint)
        {
            //TODO X Offset
            var result = VisualTreeHelper.HitTest(rootTreeView, new Point(rootTreeView.ActualWidth - 30, draggingPoint.Y));

            if (result == null)
            {
                return(null);
            }

            var overlapContainer = TreeUtil.FindVisualParent <TItem>(result.VisualHit);

            //overlapContainer 有可能是已经被折叠的子节点,故通过 IsVisible 来判断
            if (overlapContainer == null || !overlapContainer.IsVisible)
            {
                return(null);
            }

            TItem overlapItem = null;

            if (JustOverlapGroup)
            {
                if (overlapContainer.HasItems || IsGroup != null && IsGroup(overlapContainer))
                {
                    overlapItem = overlapContainer;
                }
                else
                {
                    overlapItem = ItemsControl.ItemsControlFromItemContainer(overlapContainer) as TItem;
                }
            }
            else
            {
                overlapItem = overlapContainer;
            }

            if (overlapItem != null)
            {
                var overlapItemPos = overlapItem.TranslatePoint(new Point(), rootTreeView);
                var checkHeight    = DoubleUtil.IsNaN(OverlapAreaCheckHeight) ? overlapItem.ActualHeight : OverlapAreaCheckHeight;

                if (DoubleUtil.GreaterThan(draggingPoint.Y, overlapItemPos.Y) && DoubleUtil.LessThanOrClose(draggingPoint.Y, overlapItemPos.Y + checkHeight / 2))
                {
                    _overDragArea  = OverlapArea.Inner;
                    _overDragArea |= OverlapArea.Up;
                }

                if (DoubleUtil.GreaterThan(draggingPoint.Y, overlapItemPos.Y + checkHeight / 2) && DoubleUtil.LessThanOrClose(draggingPoint.Y, overlapItemPos.Y + checkHeight))
                {
                    _overDragArea  = OverlapArea.Inner;
                    _overDragArea |= OverlapArea.Down;
                }
            }
            else
            {
                _overDragArea = OverlapArea.Inner;
            }

            return(overlapItem);
        }
Пример #3
0
        private TItem GetOverlapItem(TContainer rootTreeView, Point draggingPoint)
        {
            //TODO X Offset
            var result = VisualTreeHelper.HitTest(rootTreeView, draggingPoint);

            if (result == null)
            {
                return(null);
            }

            var overlapContainer = TreeUtil.FindVisualParent <TItem>(result.VisualHit);

            //overlapContainer 有可能是已经被折叠的子节点,故通过 IsVisible 来判断
            if (overlapContainer == null || !overlapContainer.IsVisible)
            {
                return(null);
            }

            _overDragArea = OverlapArea.Inner;

            if (overlapContainer != null)
            {
                var overlapItemPos = overlapContainer.TranslatePoint(new Point(), rootTreeView);

                if (DoubleUtil.LessThanOrClose(draggingPoint.Y, overlapItemPos.Y + overlapContainer.ActualHeight / 2))
                {
                    _overDragArea |= OverlapArea.Up;
                }
                else
                {
                    _overDragArea |= OverlapArea.Down;
                }

                if (DoubleUtil.LessThanOrClose(draggingPoint.X, overlapItemPos.X + overlapContainer.ActualWidth / 2))
                {
                    _overDragArea |= OverlapArea.Left;
                }
                else
                {
                    _overDragArea |= OverlapArea.Right;
                }
            }

            return(overlapContainer);
        }