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); }
private static void OnCellChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue == null) { return; } if (e.NewValue is string str) { var tmpArr = str.Split(_separators, StringSplitOptions.RemoveEmptyEntries); if (d is FrameworkElement fe) { if (tmpArr.Length == 2) { if (int.TryParse(tmpArr[0], out var x) && int.TryParse(tmpArr[1], out var y)) { OriginalGrid.SetColumn(fe, x); OriginalGrid.SetRow(fe, y); } else { throw new ArgumentException("Can't parse values"); } } else if (tmpArr.Length == 4) { if (int.TryParse(tmpArr[0], out var column) && int.TryParse(tmpArr[1], out var row) && int.TryParse(tmpArr[2], out var columnSpan) && int.TryParse(tmpArr[3], out var rowSpan)) { OriginalGrid.SetColumn(fe, column); OriginalGrid.SetRow(fe, row); OriginalGrid.SetColumnSpan(fe, columnSpan); OriginalGrid.SetRowSpan(fe, rowSpan); } else { throw new ArgumentException("Can't parse values"); } } else { throw new ArgumentException("Incorrect argument count for Cell value"); } } } }
/// <summary> /// Place an <see cref="UIElement" /> onto the grid. Normally a <see cref="SigmaPanel" /> should be added /// to the UI for a consistent look and feel of the UI. /// </summary> /// <param name="element">The <see cref="UIElement" /> that will be added.</param> /// <param name="row">The row in which the <see cref="UIElement" /> should be added.</param> /// <param name="column">The column in which the <see cref="UIElement" /> should be added.</param> /// <param name="rowSpan">How many rows the <see cref="UIElement" /> uses.</param> /// <param name="columnSpan">How many columns the <see cref="UIElement" /> uses.</param> /// <exception cref="ArgumentOutOfRangeException"> /// If rowSpan is smaller or equal to zero or if columnSpan /// is smaller or equal to zero. /// </exception> /// <exception cref="IndexOutOfRangeException">If there is no space for the new <see cref="UIElement" />. </exception> public void AddElement(UIElement element, int row, int column, int rowSpan = 1, int columnSpan = 1) { if (rowSpan <= 0) { throw new ArgumentOutOfRangeException(nameof(rowSpan)); } if (columnSpan <= 0) { throw new ArgumentOutOfRangeException(nameof(columnSpan)); } EnsureGridCreated(); if (row + rowSpan > GridSize.Rows) { throw new IndexOutOfRangeException("Element would be out of range! (Too few rows)"); } if (column + columnSpan > GridSize.Columns) { throw new IndexOutOfRangeException("Element would be out of range! (Too few columns)"); } Grid.Children.Add(element); WPFGrid.SetRow(element, row); WPFGrid.SetColumn(element, column); WPFGrid.SetRowSpan(element, rowSpan); WPFGrid.SetColumnSpan(element, columnSpan); //TODO: Ugly hack - otherwise it does not work if AddElement is called after Prepare if (WrappedContent.IsSelected) { WrappedContent.IsSelected = false; WrappedContent.IsSelected = true; } _log.Debug($"Added {element.GetType().Name} at {row}, {column}, with a span of {rowSpan}, {columnSpan}"); }
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); }