Esempio n. 1
0
        } // FindColumnHeader

        // ----------------------------------------------------------------------
        private void InitColumns()
        {
            var view = listView.View as GridView;

            if (view == null)
            {
                return;
            }

            foreach (GridViewColumn gridViewColumn in view.Columns)
            {
                if (RangeColumn.IsRangeColumn(gridViewColumn))
                {
                    double?minWidth = RangeColumn.GetRangeMinWidth(gridViewColumn);
                    double?maxWidth = RangeColumn.GetRangeMaxWidth(gridViewColumn);
                    if (minWidth.HasValue || maxWidth.HasValue)
                    {
                        GridViewColumnHeader columnHeader = FindColumnHeader(listView, gridViewColumn);
                        if (columnHeader == null)
                        {
                            continue;
                        }
                        if (minWidth.HasValue)
                        {
                            columnHeader.MinWidth = minWidth.Value;
                        }
                        if (maxWidth.HasValue)
                        {
                            columnHeader.MaxWidth = maxWidth.Value;
                        }
                    }
                }
            }
        } // InitColumns
Esempio n. 2
0
        } // DoResizeColumns

        // ----------------------------------------------------------------------
        private void ThumbPreviewMouseMove(object sender, MouseEventArgs e)
        {
            var            thumb          = sender as Thumb;
            GridViewColumn gridViewColumn = FindParentColumn(thumb);

            if (gridViewColumn == null)
            {
                return;
            }

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

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

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

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

                if (minWidth.HasValue && gridViewColumn.Width <= minWidth.Value)
                {
                    thumb.Cursor = Cursors.No;
                }
                else if (maxWidth.HasValue && gridViewColumn.Width >= maxWidth.Value)
                {
                    thumb.Cursor = Cursors.No;
                }
                else
                {
                    thumb.Cursor = resizeCursor; // between valid min/max
                }
            }
        } // ThumbPreviewMouseMove
Esempio n. 3
0
        } // ResizeColumns

        // ----------------------------------------------------------------------
        // returns the delta
        private double SetRangeColumnToBounds(GridViewColumn gridViewColumn)
        {
            double startWidth = gridViewColumn.Width;

            double?minWidth = RangeColumn.GetRangeMinWidth(gridViewColumn);
            double?maxWidth = RangeColumn.GetRangeMaxWidth(gridViewColumn);

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

            if (minWidth.HasValue && gridViewColumn.Width < minWidth.Value)
            {
                gridViewColumn.Width = minWidth.Value;
            }
            else if (maxWidth.HasValue && gridViewColumn.Width > maxWidth.Value)
            {
                gridViewColumn.Width = maxWidth.Value;
            }

            return(gridViewColumn.Width - startWidth);
        } // SetRangeColumnToBounds
Esempio n. 4
0
        // ----------------------------------------------------------------------
        protected virtual void ResizeColumns()
        {
            var view = listView.View as GridView;

            if (view == null || view.Columns.Count == 0)
            {
                return;
            }

            // listview width
            double actualWidth = double.PositiveInfinity;

            if (scrollViewer != null)
            {
                actualWidth = scrollViewer.ViewportWidth;
            }
            if (double.IsInfinity(actualWidth))
            {
                actualWidth = listView.ActualWidth;
            }
            if (double.IsInfinity(actualWidth) || actualWidth <= 0)
            {
                return;
            }

            double resizeableRegionCount = 0;
            double otherColumnsWidth     = 0;

            // determine column sizes
            foreach (GridViewColumn gridViewColumn in view.Columns)
            {
                if (ProportionalColumn.IsProportionalColumn(gridViewColumn))
                {
                    resizeableRegionCount += ProportionalColumn.GetProportionalWidth(gridViewColumn).Value;
                }
                else
                {
                    otherColumnsWidth += gridViewColumn.ActualWidth;
                }
            }

            if (resizeableRegionCount <= 0)
            {
                // no proportional columns present: commit the regulation to the scroll viewer
                scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

                // search the first fill column
                GridViewColumn fillColumn = null;
                for (int i = 0; i < view.Columns.Count; i++)
                {
                    GridViewColumn gridViewColumn = view.Columns[i];
                    if (IsFillColumn(gridViewColumn))
                    {
                        fillColumn = gridViewColumn;
                        break;
                    }
                }

                if (fillColumn != null)
                {
                    double otherColumnsWithoutFillWidth = otherColumnsWidth - fillColumn.ActualWidth;
                    double fillWidth = actualWidth - otherColumnsWithoutFillWidth;
                    if (fillWidth > 0)
                    {
                        double?minWidth = RangeColumn.GetRangeMinWidth(fillColumn);
                        double?maxWidth = RangeColumn.GetRangeMaxWidth(fillColumn);

                        bool setWidth = true;
                        if (minWidth.HasValue && fillWidth < minWidth.Value)
                        {
                            setWidth = false;
                        }
                        if (maxWidth.HasValue && fillWidth > maxWidth.Value)
                        {
                            setWidth = false;
                        }
                        if (setWidth)
                        {
                            scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                            fillColumn.Width = fillWidth;
                        }
                    }
                }
                return;
            }

            double resizeableColumnsWidth = actualWidth - otherColumnsWidth;

            if (resizeableColumnsWidth <= 0)
            {
                return; // missing space
            }

            // resize columns
            double resizeableRegionWidth = resizeableColumnsWidth / resizeableRegionCount;

            foreach (GridViewColumn gridViewColumn in view.Columns)
            {
                if (ProportionalColumn.IsProportionalColumn(gridViewColumn))
                {
                    gridViewColumn.Width = ProportionalColumn.GetProportionalWidth(gridViewColumn).Value *
                                           resizeableRegionWidth;
                }
            }
        } // ResizeColumns