public void ScrollContentPresenterContentScrollTest()
        {
            ScrollContentPresenterTestElement content = new ScrollContentPresenterTestElement { MeasureSize = new Size(100, 50), ExtentSize = new Size(400, 200) };
            ScrollContentPresenter scrollContentPresenter = new ScrollContentPresenter { Width = 200, Height = 100, IsRootElement = true };
            content.ViewportSize = scrollContentPresenter.RenderSize;

            scrollContentPresenter.Content = content;
            Assert.AreEqual(new Size(100, 50), scrollContentPresenter.ExtentSize);

            scrollContentPresenter.CanContentScroll = true;
            Assert.AreEqual(new Size(400, 200), scrollContentPresenter.ExtentSize);
            Assert.AreEqual(new Size(200, 100), content.LastAvailableSize1);
            Assert.IsFalse(content.CanHorizontallyScroll);
            Assert.IsFalse(content.CanVerticallyScroll);

            scrollContentPresenter.CanHorizontallyScroll = true;
            Assert.AreEqual(new Size(Double.PositiveInfinity, 100), content.LastAvailableSize2);
            Assert.IsTrue(content.CanHorizontallyScroll);
            Assert.IsFalse(content.CanVerticallyScroll);

            scrollContentPresenter.CanVerticallyScroll = true;
            Assert.AreEqual(new Size(Double.PositiveInfinity, Double.PositiveInfinity), content.LastAvailableSize2);
            Assert.IsTrue(content.CanHorizontallyScroll);
            Assert.IsTrue(content.CanVerticallyScroll);
        }
        public void ScrollContentPresenterBasicTest()
        {
            Border border = new Border();
            ScrollContentPresenter scrollContentPresenter = new ScrollContentPresenter { Width = 200, Height = 100, Content = border, IsRootElement = true };

            border.Width = 10;
            border.Height = 10;
            Assert.AreEqual(border.VisualSize, scrollContentPresenter.ExtentSize);

            border.Width = 400;
            Assert.AreEqual(border.VisualSize, scrollContentPresenter.ExtentSize);

            scrollContentPresenter.Offset = new Point(100, 0);
            Assert.AreEqual(new Point(-100, 45), border.VisualOffset);

            border.Width = 10;
            Assert.AreEqual(border.VisualSize, scrollContentPresenter.ExtentSize);
            Assert.AreEqual(new Point(95, 45), border.VisualOffset);
        }
        private void Resize()
        {
            var kind = GetAutoSize(_owner);
            if (kind != ColumnResizeKind.NoResize)
            {
                if (_columns == null)
                    TryReadColumns();

                if (_scrollContentPresenter == null)
                {
                    _scrollContentPresenter = FindPresenter();
                    if (_scrollContentPresenter != null)
                        _scrollContentPresenter.SizeChanged += new SizeChangedEventHandler(ScrollContentPresenter_SizeChanged);
                }

                if (_columns != null &&
                    _scrollContentPresenter != null)
                {
                    switch (kind)
                    {
                        case ColumnResizeKind.ByContent:
                            ResizeByContent();
                            break;
                        case ColumnResizeKind.ByControl:
                            ResizeByControl();
                            break;
                        case ColumnResizeKind.Proportional:
                            ResizeProportional();
                            break;
                    }
                }
            }
        }
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     this.scrollContentPresenter = this.Template.FindName("PART_ScrollContentPresenter", this) as ScrollContentPresenter;
 }
Beispiel #5
0
        private bool ShouldManipulateScroll(ManipulationStartingEventArgs e, ScrollContentPresenter viewport)
        {
            // If the original source is not from the same PresentationSource as of ScrollViewer,
            // then do not start the manipulation.
            if (!PresentationSource.UnderSamePresentationSource(e.OriginalSource as DependencyObject, this))
            {
                return false;
            }

            if (viewport == null)
            {
                // If there is no ScrollContentPresenter, then always start Manipulation
                return true;
            }

            // Dont start the manipulation if any of the manipulator positions
            // does not lie inside the viewport.
            GeneralTransform viewportTransform = TransformToDescendant(viewport);
            double viewportWidth = viewport.ActualWidth;
            double viewportHeight = viewport.ActualHeight;
            foreach (IManipulator manipulator in e.Manipulators)
            {
                Point manipulatorPosition = viewportTransform.Transform(manipulator.GetPosition(this));
                if (DoubleUtil.LessThan(manipulatorPosition.X, 0) ||
                    DoubleUtil.LessThan(manipulatorPosition.Y, 0) ||
                    DoubleUtil.GreaterThan(manipulatorPosition.X, viewportWidth) ||
                    DoubleUtil.GreaterThan(manipulatorPosition.Y, viewportHeight))
                {
                    return false;
                }
            }
            return true;
        }
Beispiel #6
0
        // Returns true only if element is partly visible in the current viewport
        private bool IsInViewport(ScrollContentPresenter scp, DependencyObject element)
        {
            Visual baseRoot = KeyboardNavigation.GetVisualRoot(scp);
            Visual elementRoot = KeyboardNavigation.GetVisualRoot(element);

            // If scp and element are not under the same root, find the
            // parent of root of element and try with it instead and so on.
            while (baseRoot != elementRoot)
            {
                if (elementRoot == null)
                {
                    return false;
                }

                FrameworkElement fe = elementRoot as FrameworkElement;
                if (fe == null)
                {
                    return false;
                }

                element = fe.Parent;
                if (element == null)
                {
                    return false;
                }

                elementRoot = KeyboardNavigation.GetVisualRoot(element);
            }

            Rect viewPortRect = KeyboardNavigation.GetRectangle(scp);
            Rect elementRect = KeyboardNavigation.GetRectangle(element);
            return viewPortRect.IntersectsWith(elementRect);
        }
Beispiel #7
0
        /// <summary>
        ///     Helper method which ensures the initialization of scroll controls.
        /// </summary>
        private void EnsureInternalScrollControls()
        {
            if (_internalScrollContentPresenter == null)
            {
                if (_internalItemsHost != null)
                {
                    _internalScrollContentPresenter = DataGridHelper.FindVisualParent<ScrollContentPresenter>(_internalItemsHost);
                }
                else if (_rowTrackingRoot != null)
                {
                    DataGridRow row = _rowTrackingRoot.Container;
                    _internalScrollContentPresenter = DataGridHelper.FindVisualParent<ScrollContentPresenter>(row);
                }
                if (_internalScrollContentPresenter != null)
                {
                    _internalScrollContentPresenter.SizeChanged += new SizeChangedEventHandler(OnInternalScrollContentPresenterSizeChanged);
                }
            }

            if (_internalScrollHost == null)
            {
                if (_internalItemsHost != null)
                {
                    _internalScrollHost = DataGridHelper.FindVisualParent<ScrollViewer>(_internalItemsHost);
                }
                else if (_rowTrackingRoot != null)
                {
                    DataGridRow row = _rowTrackingRoot.Container;
                    _internalScrollHost = DataGridHelper.FindVisualParent<ScrollViewer>(row);
                }
                if (_internalScrollHost != null)
                {
                    Binding horizontalOffsetBinding = new Binding("ContentHorizontalOffset");
                    horizontalOffsetBinding.Source = _internalScrollHost;
                    SetBinding(HorizontalScrollOffsetProperty, horizontalOffsetBinding);
                }
            }
        }
Beispiel #8
0
 /// <summary>
 ///     Helper method which cleans up the internal scroll controls.
 /// </summary>
 private void CleanUpInternalScrollControls()
 {
     BindingOperations.ClearBinding(this, HorizontalScrollOffsetProperty);
     _internalScrollHost = null;
     if (_internalScrollContentPresenter != null)
     {
         _internalScrollContentPresenter.SizeChanged -= new SizeChangedEventHandler(OnInternalScrollContentPresenterSizeChanged);
         _internalScrollContentPresenter = null;
     }
 }
Beispiel #9
0
        static void UpdateSelection(ScrollContentPresenter p, Rect selectionBounds, bool highlightOnly)
        {
            ListView lvControl = UITools.FindAncestor<ListView>(p);
            if (lvControl != null)
            {
                IChildInfo icInfo = UITools.FindVisualChild<Panel>(p) as IChildInfo;

                List<object> newList = new List<object>();
                List<int> newIntList = new List<int>();

                if (icInfo != null)
                {

                    for (int i = 0; i < lvControl.Items.Count; i++)
                        if (icInfo.GetChildRect(i).IntersectsWith(selectionBounds))
                        {
                            newList.Add(lvControl.Items[i]);
                            newIntList.Add(i);
                        }

                }
                else
                    //0.4 For GridView, only support selection if drag occur inside the first column
                    if (lvControl.View is GridView)
                    {
                        Point curPos = (Point)PositionCheck(GetSelectionAdorner(p), Mouse.GetPosition(p));

                        if ((lvControl.View as GridView).Columns.Count > 0)
                        {
                            double col0width = (lvControl.View as GridView).Columns[0].ActualWidth;
                            if (curPos.X < col0width || GetStartPosition(p).X < col0width)
                            {
                                if (_firstSelectedItem == null)
                                    _firstSelectedItem = getSelectedItem(p, curPos);
                                ListViewItem curSelectedItem = getSelectedItem(p, curPos);

                                if (_firstSelectedItem != null && curSelectedItem != null)
                                {

                                    int startIdx = lvControl.ItemContainerGenerator.IndexFromContainer(_firstSelectedItem);
                                    int endIdx = lvControl.ItemContainerGenerator.IndexFromContainer(curSelectedItem);

                                    for (int i = Math.Min(startIdx, endIdx); i <= Math.Max(startIdx, endIdx); i++)
                                    {
                                        newList.Add(lvControl.Items[i]);
                                        newIntList.Add(i);
                                    }
                                }
                            }
                        }
                    }

                if (highlightOnly)
                {
                    SetHighlightCount(lvControl, newIntList.Count);
                    HighlightItems(lvControl, newIntList);
                }
                else
                {
                    SetHighlightCount(lvControl, 0);
                    UnhighlightItems(lvControl);
                    UpdateSelectedItems(lvControl, newList);
                }

            }
        }
Beispiel #10
0
        static void UpdatePosition(ScrollContentPresenter p, bool highlightOnly)
        {
            ScrollViewer scrollViewer = UITools.FindAncestor<ScrollViewer>(p);
            SelectionAdorner _adorner = GetSelectionAdorner(p);

            if (GetIsDragging(p))
            {
                Point startScrollbarPosition = GetStartScrollbarPosition(p);
                Point curScrollbarPosition = GetScrollbarPosition(p);
                Point startPosition = GetStartPosition(p);
                Point curPosition = Mouse.GetPosition(p);

                if (!_adorner.IsSelecting)
                {
                    if (Math.Abs(startPosition.X - curPosition.X) > SystemParameters.MinimumHorizontalDragDistance ||
                        Math.Abs(startPosition.Y - curPosition.Y) > SystemParameters.MinimumVerticalDragDistance)
                    {
                        _adorner.IsSelecting = true;
                        Mouse.Capture(p);
                    }
                }
                else
                {
                    Vector offset = Point.Subtract(startScrollbarPosition, curScrollbarPosition);
                    _adorner.StartPosition = Point.Add(startPosition, offset);
                    _adorner.EndPosition = curPosition;
                    UpdateSelection(p, new Rect(
                        new Point(startPosition.X + startScrollbarPosition.X, startPosition.Y + startScrollbarPosition.Y),
                        new Point(curPosition.X + curScrollbarPosition.X, curPosition.Y + curScrollbarPosition.Y)), highlightOnly);
                }
            }
        }
Beispiel #11
0
        static ListViewItem getSelectedItem(ScrollContentPresenter lvSender, Point position)
        {
            HitTestResult r = VisualTreeHelper.HitTest(lvSender, position);
            if (r == null) return null;

            DependencyObject obj = r.VisualHit;
            while (!(obj is ListView) && (obj != null))
            {
                obj = VisualTreeHelper.GetParent(obj);

                if (obj is ListViewItem)
                    return obj as ListViewItem;
            }

            return null;
        }
Beispiel #12
0
 static Point GetScrollbarPosition(ScrollContentPresenter p)
 {
     ScrollViewer scrollViewer = UITools.FindAncestor<ScrollViewer>(p);
     return new Point(p.ActualWidth / scrollViewer.ViewportWidth * scrollViewer.HorizontalOffset,
         p.ActualHeight / scrollViewer.ViewportHeight * scrollViewer.VerticalOffset);
 }
Beispiel #13
0
 static void EndDragging(ScrollContentPresenter p)
 {
     SelectionAdorner _adorner = GetSelectionAdorner(p);
     if (_adorner.IsSelecting)
     {
         UpdatePosition(p, false);
         _adorner.IsSelecting = false;
         SetIsDragging(p, false);
     }
 }
Beispiel #14
0
 static void BeginDragging(ScrollContentPresenter p)
 {
     SetStartScrollbarPosition(p, GetScrollbarPosition(p));
     SetIsDragging(p, true);
 }
Beispiel #15
0
 public static void SetLastScrollContentPresenter(DependencyObject target, ScrollContentPresenter value)
 {
     target.SetValue(LastScrollContentPresenterProperty, value);
 }
Beispiel #16
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (Template != null)
            {
                scrollContentPresenter = Template.FindName("PART_ScrollContentPresenter", this) as ScrollContentPresenter;
                HorizontalScrollBar = Template.FindName("PART_HorizontalScrollBar", this) as ScrollBar;
                VerticalScrollBar = Template.FindName("PART_VerticalScrollBar", this) as ScrollBar;
            }
            else
            {
                scrollContentPresenter = null;
                HorizontalScrollBar = null;
                VerticalScrollBar = null;
            }

            SetContentCanScroll();
            SetScrollInfoSizes();
        }