Exemplo n.º 1
0
        private void ThumbPreviewMouseMove(object sender, MouseEventArgs e)
        {
            var thumb = sender as Thumb;

            if (thumb is null)
            {
                return;
            }
            var gridViewColumn = FindParentColumn(thumb);

            if (gridViewColumn is null)
            {
                return;
            }

            // suppress column resizing for proportional, fixed and range fill columns
            if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn) || IsFillColumn(gridViewColumn))
            {
                thumb.SetCurrentValue(FrameworkElement.CursorProperty, null);
                return;
            }

            // check range column bounds
            if (thumb.IsMouseCaptured && RangeColumn.IsRangeColumn(gridViewColumn))
            {
                var minWidth = RangeColumn.GetRangeMinWidth(gridViewColumn);
                var maxWidth = RangeColumn.GetRangeMaxWidth(gridViewColumn);

                if (minWidth.HasValue && maxWidth.HasValue && (minWidth > maxWidth))
                {
                    return; // invalid case
                }

                if (_resizeCursor is null)
                {
                    _resizeCursor = thumb.Cursor; // save the resize cursor
                }

                if (minWidth.HasValue && gridViewColumn.Width <= minWidth.Value)
                {
                    thumb.SetCurrentValue(FrameworkElement.CursorProperty, Cursors.No);
                }
                else if (maxWidth.HasValue && gridViewColumn.Width >= maxWidth.Value)
                {
                    thumb.SetCurrentValue(FrameworkElement.CursorProperty, Cursors.No);
                }
                else
                {
                    thumb.SetCurrentValue(FrameworkElement.CursorProperty, _resizeCursor); // between valid min/max
                }
            }
        }
Exemplo n.º 2
0
        private void ThumbPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is Thumb thumb))
            {
                return;
            }

            var gridViewColumn = FindParentColumn(thumb);

            // suppress column resizing for proportional, fixed and range fill columns
            if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn) || IsFillColumn(gridViewColumn))
            {
                e.Handled = true;
            }
        }
Exemplo n.º 3
0
        private void RegisterEvents(DependencyObject?start)
        {
            if (start is null)
            {
                return;
            }

            for (var i = 0; i < VisualTreeHelper.GetChildrenCount(start); i++)
            {
                var childVisual = VisualTreeHelper.GetChild(start, i) as Visual;
                if (childVisual is Thumb)
                {
                    var gridViewColumn = FindParentColumn(childVisual);
                    if (gridViewColumn != null)
                    {
                        if (childVisual is Thumb thumb)
                        {
                            if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn) || IsFillColumn(gridViewColumn))
                            {
                                thumb.SetCurrentValue(UIElement.IsHitTestVisibleProperty, false);
                            }
                            else
                            {
                                thumb.PreviewMouseMove           += new MouseEventHandler(ThumbPreviewMouseMove);
                                thumb.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(ThumbPreviewMouseLeftButtonDown);
                                DependencyPropertyDescriptor.FromProperty(
                                    GridViewColumn.WidthProperty,
                                    typeof(GridViewColumn)).AddValueChanged(gridViewColumn, GridColumnWidthChanged);
                            }
                        }
                    }
                }
                else if (childVisual is GridViewColumnHeader columnHeader)
                {
                    columnHeader.SizeChanged += new SizeChangedEventHandler(GridColumnHeaderSizeChanged);
                }
                else if (_scrollViewer is null && childVisual is ScrollViewer scrollViewer)
                {
                    _scrollViewer = scrollViewer;
                    _scrollViewer.ScrollChanged += new ScrollChangedEventHandler(ScrollViewerScrollChanged);

                    // assume we do the regulation of the horizontal scrollbar
                    _scrollViewer.SetCurrentValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);
                    _scrollViewer.SetCurrentValue(ScrollViewer.VerticalScrollBarVisibilityProperty, VerticalScrollBarVisibility);
                }

                RegisterEvents(childVisual);
            }
        }
Exemplo n.º 4
0
        private void UnregisterEvents(DependencyObject?start)
        {
            if (start is null)
            {
                return;
            }

            for (var i = 0; i < VisualTreeHelper.GetChildrenCount(start); i++)
            {
                var childVisual = VisualTreeHelper.GetChild(start, i) as Visual;
                if (childVisual is Thumb)
                {
                    var gridViewColumn = FindParentColumn(childVisual);
                    if (gridViewColumn != null)
                    {
                        if (childVisual is Thumb thumb)
                        {
                            if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn) || IsFillColumn(gridViewColumn))
                            {
                                thumb.SetCurrentValue(UIElement.IsHitTestVisibleProperty, true);
                            }
                            else
                            {
                                thumb.PreviewMouseMove           -= new MouseEventHandler(ThumbPreviewMouseMove);
                                thumb.PreviewMouseLeftButtonDown -= new MouseButtonEventHandler(ThumbPreviewMouseLeftButtonDown);
                                DependencyPropertyDescriptor.FromProperty(
                                    GridViewColumn.WidthProperty,
                                    typeof(GridViewColumn)).RemoveValueChanged(gridViewColumn, GridColumnWidthChanged);
                            }
                        }
                    }
                }
                else if (childVisual is GridViewColumnHeader columnHeader)
                {
                    columnHeader.SizeChanged -= new SizeChangedEventHandler(GridColumnHeaderSizeChanged);
                }
                else if (_scrollViewer is null && childVisual is ScrollViewer scrollViewer)
                {
                    _scrollViewer = scrollViewer;
                    _scrollViewer.ScrollChanged -= new ScrollChangedEventHandler(ScrollViewerScrollChanged);
                }

                UnregisterEvents(childVisual);
            }
        }