示例#1
0
        private void DragScrollBegin(Orientation orientation)
        {
            if (!this.ShouldDisplayScrollTip)
            {
                return;
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (dataGridContext == null)
            {
                return;
            }

            if (dataGridContext.DataGridControl == null)
            {
                return;
            }

            // Update items scrolling orientation and pixel scrolling
            m_itemsScrollingOrientation = ScrollViewerHelper.GetItemScrollingOrientation(dataGridContext.DataGridControl);

            if (m_itemsScrollingOrientation != orientation)
            {
                return;
            }

            this.Visibility = Visibility.Visible;

            this.IsPixelScrolling = ScrollViewerHelper.IsPixelScrolling(dataGridContext.DataGridControl, dataGridContext.DataGridControl.ItemsHost, dataGridContext.DataGridControl.ScrollViewer);

            this.RefreshScrollTipContent(m_scrollViewerTemplateHelper.GetScrollBar(orientation));
        }
示例#2
0
        private static FrameworkElement ProcessFirstVisibleContainer(
            DataGridControl gridControl,
            double offset,
            double viewportSize,
            double opposedOffset,
            double opposedViewportSize,
            Orientation panelOrientation)
        {
            FrameworkElement retval = null;

            // Only needed if the DataGridControl contains items
            if ((gridControl != null) && (gridControl.Items.Count > 0))
            {
                bool qualifyingContainerFound = false;

                //retrieve the last object index according to item scrolling axis (this covers both the "Vertical and None" primary axis cases...
                //as well as default if no other row matches the PrimaryAxis criteria)
                int runningIndex = ( int )(offset);

                //cycle for as long as a qualifying container is not found.
                while (!qualifyingContainerFound)
                {
                    retval = gridControl.GetContainerFromIndex(runningIndex) as FrameworkElement;

                    //will be reverted back if the container does not match a particular condition.
                    if (retval != null)
                    {
                        qualifyingContainerFound = ScrollViewerHelper.IsContainerQualifying(retval,
                                                                                            gridControl,
                                                                                            offset,
                                                                                            viewportSize,
                                                                                            opposedOffset,
                                                                                            opposedViewportSize,
                                                                                            panelOrientation);
                    }

                    //under all circumstances, if I am back at the end of the viewport ( last item visible), then have it qualify.
                    if (runningIndex == (offset + viewportSize - 1))
                    {
                        qualifyingContainerFound = true;
                    }

                    runningIndex++;
                }
            }

            return(retval);
        }
示例#3
0
        public static FrameworkElement GetLastVisibleContainer(
            DataGridControl gridControl,
            FrameworkElement container,
            ScrollViewer scrollViewer)
        {
            FrameworkElement retval = null;

            if (ScrollViewerHelper.IsPixelScrolling(gridControl, container, scrollViewer) == false)
            {
                //This means that the panel is performing Item Scrolling

                //if the panel is Vertically scrolling the items (means the Horizontal Axis is Pixel scrolling)
                if (ScrollViewerHelper.GetItemScrollingOrientation(gridControl, container, scrollViewer) == Orientation.Vertical)
                {
                    retval = ScrollViewerHelper.ProcessLastVisibleContainer(gridControl,
                                                                            scrollViewer.VerticalOffset,
                                                                            scrollViewer.ViewportHeight,
                                                                            scrollViewer.HorizontalOffset,
                                                                            scrollViewer.ViewportWidth,
                                                                            Orientation.Vertical);
                }
                //the panel is Horizontally scrolling the items (means the Vertically Axis is Pixel scrolling)
                else
                {
                    retval = ScrollViewerHelper.ProcessLastVisibleContainer(gridControl,
                                                                            scrollViewer.HorizontalOffset,
                                                                            scrollViewer.ViewportWidth,
                                                                            scrollViewer.VerticalOffset,
                                                                            scrollViewer.ViewportHeight,
                                                                            Orientation.Horizontal);
                }
            }
            else
            {
                Point pt = new Point();

                if ((container is VirtualizingPanel) ||
                    (container is DataGridItemsHost) ||
                    (scrollViewer == null))
                {
                    pt.X = 0;
                    pt.Y = 0;
                }
                else
                {
                    pt.X = scrollViewer.HorizontalOffset;
                    pt.Y = scrollViewer.VerticalOffset;
                }

                Size size = new Size((scrollViewer != null) ? scrollViewer.ViewportWidth : container.ActualWidth,
                                     (scrollViewer != null) ? scrollViewer.ViewportHeight : container.ActualHeight);

                Rect visibleRect = new Rect(pt, size);

                RectangleGeometry geo = new RectangleGeometry(visibleRect);

                lock (ScrollViewerHelper.Current)
                {
                    m_sVisibleChildList.Clear();
                    m_sGridControl = gridControl;

                    VisualTreeHelper.HitTest(container,
                                             new HitTestFilterCallback(ScrollViewerHelper.MyFilterFunct),
                                             new HitTestResultCallback(ScrollViewerHelper.UselessResultCallback),
                                             new GeometryHitTestParameters(geo));

                    m_sGridControl = null;

                    FrameworkElement  preservedChild  = null;
                    Nullable <Vector> preservedOffset = null;

                    foreach (FrameworkElement child in m_sVisibleChildList)
                    {
                        Vector itemOffset = VisualTreeHelper.GetOffset(child);

                        Rect itemRect = new Rect(itemOffset.X, itemOffset.Y, child.ActualWidth, child.ActualHeight);

                        itemRect.Intersect(visibleRect);

                        switch (gridControl.ItemsPrimaryAxis)
                        {
                        case PrimaryAxis.Vertical:
                            if (DoubleUtil.AreClose(itemRect.Width, 0) == false)
                            {
                                if (DoubleUtil.AreClose(itemRect.Height, child.ActualHeight) == true)
                                {
                                    if (ScrollViewerHelper.IsABetterLastRow(preservedChild, preservedOffset, itemOffset) == true)
                                    {
                                        preservedChild  = child;
                                        preservedOffset = itemOffset;
                                    }
                                }
                            }
                            break;

                        case PrimaryAxis.Horizontal:
                            if (DoubleUtil.AreClose(itemRect.Width, child.ActualWidth) == true)
                            {
                                if (DoubleUtil.AreClose(itemRect.Height, 0) == false)
                                {
                                    if (ScrollViewerHelper.IsABetterLastRow(preservedChild, preservedOffset, itemOffset) == true)
                                    {
                                        preservedChild  = child;
                                        preservedOffset = itemOffset;
                                    }
                                }
                            }
                            break;

                        case PrimaryAxis.Both:
                            if ((DoubleUtil.AreClose(itemRect.Width, child.ActualWidth) == true) &&
                                (DoubleUtil.AreClose(itemRect.Height, child.ActualHeight) == true))
                            {
                                if (ScrollViewerHelper.IsABetterLastRow(preservedChild, preservedOffset, itemOffset) == true)
                                {
                                    preservedChild  = child;
                                    preservedOffset = itemOffset;
                                }
                            }
                            break;

                        case PrimaryAxis.None:
                            if (itemRect.IsEmpty == false)
                            {
                                if ((DoubleUtil.AreClose(itemRect.Height, 0) == false) && (DoubleUtil.AreClose(itemRect.Width, 0) == false))
                                {
                                    if (ScrollViewerHelper.IsABetterLastRow(preservedChild, preservedOffset, itemOffset) == true)
                                    {
                                        preservedChild  = child;
                                        preservedOffset = itemOffset;
                                    }
                                }
                            }
                            break;
                        }
                    }

                    retval = preservedChild;
                }//end lock (protection of shared static members with GetFirstVisibleItem() )
            }


            return(retval);
        }
示例#4
0
        private void ScrollThumb_IsMouseCapturedChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Thumb scrollThumb = sender as Thumb;

            if (scrollThumb == null)
            {
                return;
            }

            if (!scrollThumb.IsMouseCaptured)
            {
                return;
            }

            if (!this.ShouldDisplayScrollTip)
            {
                return;
            }

            ScrollBar scrollBar = scrollThumb.TemplatedParent as ScrollBar;

            if (scrollBar == null)
            {
                return;
            }

            // Register to LostMouseCapture to be sure to hide the ScrollTip when the ScrollThumb lost the focus
            if (scrollThumb == m_horizontalScrollThumb)
            {
                m_horizontalScrollThumb.LostMouseCapture += new MouseEventHandler(this.ScrollThumb_LostMouseCapture);
            }
            else if (scrollThumb == m_verticalScrollThumb)
            {
                m_verticalScrollThumb.LostMouseCapture += new MouseEventHandler(this.ScrollThumb_LostMouseCapture);
            }
            else
            {
                Debug.Fail("Unknown thumb used for scrolling.");
                return;
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (dataGridContext == null)
            {
                return;
            }

            if (dataGridContext.DataGridControl == null)
            {
                return;
            }

            // Update items scrolling orientation and pixel scrolling
            m_itemsScrollingOrientation = ScrollViewerHelper.GetItemScrollingOrientation(dataGridContext.DataGridControl);

            if (m_itemsScrollingOrientation == Orientation.Vertical)
            {
                if (scrollBar != m_verticalScrollBar)
                {
                    return;
                }
            }
            else
            {
                if (scrollBar != m_horizontalScrollBar)
                {
                    return;
                }
            }

            this.Visibility = Visibility.Visible;

            this.IsPixelScrolling = ScrollViewerHelper.IsPixelScrolling(dataGridContext.DataGridControl, dataGridContext.DataGridControl.ItemsHost, dataGridContext.DataGridControl.ScrollViewer);

            this.RefreshScrollTipContent(scrollBar);
        }