Пример #1
0
        private TreeViewItemEx GetPageUpDownContainer(TreeViewItemEx container, bool down)
        {
            if (container == null)
            {
                return(down ? GetLastContainer(this, true) : GetFirstContainer(this, true));
            }

            double yThreshold     = container.TransformToAncestor(this).Transform(new Point()).Y;
            double itemHeight     = container.HeaderHeight;
            double viewportHeight = _scrollViewer?.ViewportHeight ?? ActualHeight;
            double offset         = viewportHeight - 2 * itemHeight;

            if (down)
            {
                yThreshold += offset;
                var nextContainer = GetNextContainer(container, true);
                while (nextContainer != null)
                {
                    container = nextContainer;
                    double y = container.TransformToAncestor(this).Transform(new Point()).Y;
                    if (y > yThreshold)
                    {
                        break;
                    }

                    nextContainer = GetNextContainer(nextContainer, true);
                }
            }
            else
            {
                yThreshold -= offset;
                var previousContainer = GetPreviousContainer(container, true);
                while (previousContainer != null)
                {
                    container = previousContainer;
                    double y = container.TransformToAncestor(this).Transform(new Point()).Y;
                    if (y < yThreshold)
                    {
                        break;
                    }

                    previousContainer = GetPreviousContainer(previousContainer, true);
                }
            }

            return(container);
        }
Пример #2
0
        private TreeViewItemEx GetPageUpDownContainer(TreeViewItemEx container, bool down)
        {
            if (container == null)
                return down ? GetLastContainer(this, true) : GetFirstContainer(this, true);

            double yThreshold = container.TransformToAncestor(this).Transform(new Point()).Y;
            double itemHeight = container.HeaderHeight;
            double viewportHeight = _scrollViewer?.ViewportHeight ?? ActualHeight;
            double offset = viewportHeight - 2 * itemHeight;

            if (down)
            {
                yThreshold += offset;
                var nextContainer = GetNextContainer(container, true);
                while (nextContainer != null)
                {
                    container = nextContainer;
                    double y = container.TransformToAncestor(this).Transform(new Point()).Y;
                    if (y > yThreshold)
                        break;

                    nextContainer = GetNextContainer(nextContainer, true);
                }
            }
            else
            {
                yThreshold -= offset;
                var previousContainer = GetPreviousContainer(container, true);
                while (previousContainer != null)
                {
                    container = previousContainer;
                    double y = container.TransformToAncestor(this).Transform(new Point()).Y;
                    if (y < yThreshold)
                        break;

                    previousContainer = GetPreviousContainer(previousContainer, true);
                }
            }

            return container;
        }