public void Resize(ColumnBase gridColumn, double diff) { Rows rows = new Rows(this); CorrectColumnsWidth(rows); if (diff == 0d || double.IsNaN(diff)) { return; } int columnIndex = BandedViewBehavior.GetColumn(gridColumn); int rowIndex = BandedViewBehavior.GetRow(gridColumn); Row row = rows[rowIndex]; row.SelectColumn(columnIndex); if (diff > 0) { DecreaseColumnsWidth(row, row.SelectedIndex + 1, ref diff); IncreaseSelectedColumnWidth(row, diff); } if (diff < 0) { diff *= -1; if (Math.Abs(row.SelectedCell.ActualWidth - row.SelectedCell.ColumnMinWidth) <= 0.5) { return; } DecreaseSelectedColumnWidth(row, ref diff); IncreaseColumnsWidth(row, row.SelectedIndex + 1, diff); } row.Foreach(row.SelectedIndex, (rowCell) => { double res = rowCell.NewWidth / row.RowWidth; rowCell.ColumnWidth = new GridLength(res, GridUnitType.Star); }); }
void PrepareChild(ContentPresenter child, ColumnBase column) { int columnCorrectingCoef = BandedViewBehavior.GetIsLeftColumn(column) ? 0 : 1; int columnSpanCorrectingCoef = BandedViewBehavior.GetIsLeftColumn(column) ? 1 : 0; StdGrid.SetRow(child, BandedViewBehavior.GetRow(column)); StdGrid.SetColumn(child, BandedViewBehavior.GetColumn(column) + columnCorrectingCoef); StdGrid.SetRowSpan(child, BandedViewBehavior.GetRowSpan(column)); StdGrid.SetColumnSpan(child, BandedViewBehavior.GetColumnSpan(column) + columnSpanCorrectingCoef); }
public RowCell(ResizableGrid owner, ColumnBase gridColumn, ContentPresenter contentPresenter) : base(owner) { GridColumnPresenter = contentPresenter; GridColumn = gridColumn; Row = BandedViewBehavior.GetRow(GridColumn); RowSpan = BandedViewBehavior.GetRowSpan(GridColumn); Column = BandedViewBehavior.GetColumn(GridColumn); ColumnSpan = BandedViewBehavior.GetColumnSpan(GridColumn); ColumnDefinitions = new ColumnDefinitions(); for (int i = Column; i < Column + ColumnSpan; i++) { ColumnDefinitions.Add(Owner.BandBehavior.ColumnDefinitions[i]); } }
protected override FrameworkElement CreateChild(object item) { GridCellData cellData = (GridCellData)item; ColumnBase gridColumn = cellData.Column; AutoWidthCellContentPresenter presenter = new AutoWidthCellContentPresenter(); int row = BandedViewBehavior.GetRow(gridColumn); int column = BandedViewBehavior.GetColumn(gridColumn) + 1; int rowSpan = BandedViewBehavior.GetRowSpan(gridColumn); int columnSpan = BandedViewBehavior.GetColumnSpan(gridColumn); StdGrid.SetRow(presenter, row); StdGrid.SetColumn(presenter, column); StdGrid.SetRowSpan(presenter, rowSpan); StdGrid.SetColumnSpan(presenter, columnSpan); if (BandedViewBehavior.GetIsBand(gridColumn)) { presenter.Visibility = Visibility.Collapsed; } else { presenter.Visibility = Visibility.Visible; } return(presenter); }