示例#1
0
        /// <summary>
        /// Applies the bound to the given grid.
        /// </summary>
        /// <param name="pColumn">The column to bound.</param>
        /// <returns>The resize delta after applying the bound.</returns>
        private double SetRangeColumnToBounds(GridViewColumn pColumn)
        {
            if (RangeColumn.IsRangeColumn(pColumn) == false)
            {
                // No need to resize.
                return(0);
            }

            double lStartWidth = pColumn.Width;

            double?lMinWidth = RangeColumn.GetRangeMinWidth(pColumn);
            double?lMaxWidth = RangeColumn.GetRangeMaxWidth(pColumn);

            if ((lMinWidth.HasValue && lMaxWidth.HasValue) && (lMinWidth > lMaxWidth))
            {
                // Invalid case. No resize.
                return(0);
            }

            // Bounding the width.
            if (lMinWidth.HasValue && pColumn.Width < lMinWidth.Value)
            {
                pColumn.Width = lMinWidth.Value;
            }
            else if (lMaxWidth.HasValue && pColumn.Width > lMaxWidth.Value)
            {
                pColumn.Width = lMaxWidth.Value;
            }

            return(pColumn.Width - lStartWidth);
        }
示例#2
0
        /// <summary>
        /// Delegate called when a mouse is mouving on a thumb.
        /// </summary>
        /// <param name="pSender">The event sender.</param>
        /// <param name="pEventArgs">The event arguments.</param>
        private void OnThumbPreviewMouseMove(object pSender, MouseEventArgs pEventArgs)
        {
            Thumb lThumb = pSender as Thumb;

            if (lThumb == null)
            {
                return;
            }

            GridViewColumn lColumn = this.FindParentColumn(lThumb);

            if (lColumn == null)
            {
                return;
            }

            // Suppress column resizing for fixed and range fill columns.
            if (FixedColumn.IsFixedColumn(lColumn) || this.IsFillColumn(lColumn))
            {
                // Cursor is hidden.
                lThumb.Cursor = null;
                return;
            }

            // Check range column bounds.
            if (lThumb.IsMouseCaptured && RangeColumn.IsRangeColumn(lColumn))
            {
                double?lMinWidth = RangeColumn.GetRangeMinWidth(lColumn);
                double?lMaxWidth = RangeColumn.GetRangeMaxWidth(lColumn);

                if ((lMinWidth.HasValue && lMaxWidth.HasValue) && (lMinWidth > lMaxWidth))
                {
                    // Invalid case.
                    return;
                }

                if (this.mBackCursor == null)
                {
                    // First time = save the resize cursor.
                    this.mBackCursor = lThumb.Cursor;
                }

                // Updating the cursor.
                if (lMinWidth.HasValue && lColumn.Width <= lMinWidth.Value)
                {
                    lThumb.Cursor = Cursors.No;
                }
                else if (lMaxWidth.HasValue && lColumn.Width >= lMaxWidth.Value)
                {
                    lThumb.Cursor = Cursors.No;
                }
                else
                {
                    lThumb.Cursor = this.mBackCursor;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Initialize the columns by applying there properties.
        /// </summary>
        private void InitColumns()
        {
            if (this.mListView.View == null)
            {
                return;
            }

            foreach (GridViewColumn lColumn in this.mListView.View.Columns)
            {
                if (RangeColumn.IsRangeColumn(lColumn) == false)
                {
                    continue;
                }

                double?lMinWidth = RangeColumn.GetRangeMinWidth(lColumn);
                double?lMaxWidth = RangeColumn.GetRangeMaxWidth(lColumn);
                if (lMinWidth.HasValue == false && lMaxWidth.HasValue == false)
                {
                    continue;
                }

                GridViewColumnHeader lColumnHeader = this.FindColumnHeader(this.mListView, lColumn);
                if (lColumnHeader == null)
                {
                    continue;
                }

                double lActualWidth = lColumnHeader.ActualWidth;
                if (lMinWidth.HasValue)
                {
                    lColumnHeader.MinWidth = lMinWidth.Value;
                    if (!double.IsInfinity(lActualWidth) && lActualWidth < lColumnHeader.MinWidth)
                    {
                        lColumn.Width = lColumnHeader.MinWidth;
                    }
                }

                if (lMaxWidth.HasValue)
                {
                    lColumnHeader.MaxWidth = lMaxWidth.Value;
                    if (double.IsInfinity(lActualWidth) == false && lActualWidth > lColumnHeader.MaxWidth)
                    {
                        lColumn.Width = lColumnHeader.MaxWidth;
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Resizes the grid view columns.
        /// </summary>
        /// <param name="pColumnIndex">The specific index of the resized column, or -1 if the whole control is resized.</param>
        private void ResizeColumns(int pColumnIndex)
        {
            if (this.mListView.View == null || this.mListView.View.Columns.Count == 0)
            {
                return;
            }

            // Computing the listview width.
            double lActualWidth = double.PositiveInfinity;

            if (mScrollViewer != null)
            {
                lActualWidth = this.mScrollViewer.ViewportWidth;
            }
            if (double.IsInfinity(lActualWidth))
            {
                lActualWidth = this.mListView.ActualWidth;
            }
            if (double.IsInfinity(lActualWidth) || lActualWidth <= 0)
            {
                return;
            }

            // Computing column sizes.
            double lResizeableRegionCount = 0;
            double lOtherColumnsWidth     = 0;

            foreach (GridViewColumn lColumn in this.mListView.View.Columns)
            {
                if (ProportionalColumn.IsProportionalColumn(lColumn))
                {
                    double?lProportionalWidth = ProportionalColumn.GetProportionalWidth(lColumn);
                    if (lProportionalWidth != null)
                    {
                        lResizeableRegionCount += lProportionalWidth.Value;
                    }
                }
                else
                {
                    lOtherColumnsWidth += lColumn.ActualWidth;
                }
            }

            if (lResizeableRegionCount <= 0)
            {
                // No proportional columns present : commit the regulation to the scroll viewer.
                if (this.mScrollViewer != null)
                {
                    this.mScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                }

                // Searching for the first fill column.
                GridViewColumn lFillColumn = null;
                for (int lIter = 0; lIter < this.mListView.View.Columns.Count; lIter++)
                {
                    GridViewColumn lColumn = this.mListView.View.Columns[lIter];
                    if (IsFillColumn(lColumn))
                    {
                        lFillColumn = lColumn;
                        break;
                    }
                }

                if (lFillColumn != null)
                {
                    // Applying the width to the fill column taking in account the range.
                    double lOtherColumnsWithoutFillWidth = lOtherColumnsWidth - lFillColumn.ActualWidth;
                    double lFillWidth = lActualWidth - lOtherColumnsWithoutFillWidth;
                    if (lFillWidth > 0)
                    {
                        double?lMinWidth = RangeColumn.GetRangeMinWidth(lFillColumn);
                        double?lMaxWidth = RangeColumn.GetRangeMaxWidth(lFillColumn);

                        bool lSetWidth = (lMinWidth.HasValue && lFillWidth < lMinWidth.Value) == false;
                        if (lMaxWidth.HasValue && lFillWidth > lMaxWidth.Value)
                        {
                            lSetWidth = false;
                        }

                        if (lSetWidth)
                        {
                            if (this.mScrollViewer != null)
                            {
                                this.mScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                            }
                            lFillColumn.Width = lFillWidth;
                        }
                    }
                }
                return;
            }

            // Some proportional columns have been defined.
            double lResizeableColumnsWidth = lActualWidth - lOtherColumnsWidth;

            if (lResizeableColumnsWidth <= 0)
            {
                // Missing space.
                return;
            }

            // Resize proportional columns.
            double lResizeableRegionWidth = lResizeableColumnsWidth / lResizeableRegionCount;

            foreach (GridViewColumn lColumn in this.mListView.View.Columns)
            {
                if (ProportionalColumn.IsProportionalColumn(lColumn))
                {
                    if (pColumnIndex == -1)
                    {
                        // Computing the initial width.
                        double?lProportionalWidth = ProportionalColumn.GetProportionalWidth(lColumn);
                        if (lProportionalWidth != null)
                        {
                            lColumn.Width = lProportionalWidth.Value * lResizeableRegionWidth;
                        }
                    }
                    else
                    {
                        int lCurrentIndex = this.mListView.View.Columns.IndexOf(lColumn);
                        if (pColumnIndex == lCurrentIndex)
                        {
                            // Adapting the ratio so that the column can be resized.
                            ProportionalColumn.ApplyWidth(lColumn, lColumn.Width / lResizeableRegionWidth);
                        }
                        else if (lCurrentIndex > pColumnIndex)
                        {
                            // Computing the initial width for the colums after the one resized.
                            double?proportionalWidth = ProportionalColumn.GetProportionalWidth(lColumn);
                            if (proportionalWidth != null)
                            {
                                lColumn.Width = proportionalWidth.Value * lResizeableRegionWidth;
                            }
                        }
                    }
                }
            }
        }