public void RemoveColumn(GridElement grid, int index) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitRemoveGridline)) { grid.ViewModel.GridColumnSelectionSet.Clear(); grid.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)grid.ColumnDefinitions[index]); using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); bool isStar1 = grid.ColumnDefinitions[index - 1].Width.IsStar; bool isStar2 = grid.ColumnDefinitions[index].Width.IsStar; List <int> widthStarIndices = this.GetWidthStarIndices(grid); grid.CacheComputedColumnWidths(); List <double> columnWidthCache; int index1; (columnWidthCache = grid.ComputedColumnWidthCache)[index1 = index - 1] = columnWidthCache[index1] + grid.ComputedColumnWidthCache[index]; grid.ComputedColumnWidthCache.RemoveAt(index); grid.ColumnDefinitions.RemoveAt(index); if (isStar2) { widthStarIndices.Remove(index); } if (isStar1 || isStar2) { for (int index2 = 0; index2 < widthStarIndices.Count; ++index2) { if (widthStarIndices[index2] > index) { List <int> list; int index3; (list = widthStarIndices)[index3 = index2] = list[index3] - 1; } } this.NormalizeWidthStars(grid, widthStarIndices); } if (!isStar1) { grid.ColumnDefinitions[index - 1].Width = new GridLength(grid.ComputedColumnWidthCache[index - 1]); grid.ColumnDefinitions[index - 1].ClearValue(ColumnDefinitionNode.MinWidthProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedColumnWidths(); GridLayoutDesigner.ReselectGridToRestoreAdorners(grid); editTransaction.Commit(); } } }
public void AddVerticalGridline(GridElement grid, double position) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitAddGridline)) { using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); int columnBeforePosition = grid.GetComputedColumnBeforePosition(position); double positionOfColumn1 = grid.GetComputedPositionOfColumn(columnBeforePosition); double positionOfColumn2 = grid.GetComputedPositionOfColumn(columnBeforePosition + 1); bool flag = grid.ColumnDefinitions.Count == 0 || grid.ColumnDefinitions[columnBeforePosition].Width.IsStar; grid.CacheComputedColumnWidths(); this.EnsureOneColumn(grid); grid.ColumnDefinitions.Insert(columnBeforePosition + 1, ColumnDefinitionNode.Factory.Instantiate(grid.ViewModel)); position = Math.Max(position, positionOfColumn1); if (position > positionOfColumn2) { grid.ComputedColumnWidthCache[columnBeforePosition] = positionOfColumn2 - positionOfColumn1; grid.ComputedColumnWidthCache.Insert(columnBeforePosition + 1, position - positionOfColumn2); } else { grid.ComputedColumnWidthCache[columnBeforePosition] = position - positionOfColumn1; grid.ComputedColumnWidthCache.Insert(columnBeforePosition + 1, positionOfColumn2 - position); } editTransaction.Update(); grid.ViewModel.DefaultView.UpdateLayout(); if (flag) { List <int> widthStarIndices = this.GetWidthStarIndices(grid); this.NormalizeWidthStars(grid, widthStarIndices); } else { grid.ColumnDefinitions[columnBeforePosition].Width = new GridLength(grid.ComputedColumnWidthCache[columnBeforePosition]); grid.ColumnDefinitions[columnBeforePosition].ClearValue(ColumnDefinitionNode.MinWidthProperty); grid.ColumnDefinitions[columnBeforePosition + 1].Width = new GridLength(grid.ComputedColumnWidthCache[columnBeforePosition + 1]); grid.ColumnDefinitions[columnBeforePosition + 1].ClearValue(ColumnDefinitionNode.MinWidthProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedColumnWidths(); editTransaction.Commit(); } } grid.ViewModel.DefaultView.AdornerLayer.InvalidateAdornersStructure((SceneElement)grid); }
protected override sealed bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow) { if (this.CanInsert) { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.ShapeCreateBehaviorOnDrag); if (!this.IsEditTransactionOpen) { GridElement gridElement = this.ActiveSceneInsertionPoint.SceneElement as GridElement; if (gridElement != null) { gridElement.CacheComputedColumnWidths(); gridElement.CacheComputedRowHeights(); } this.EnsureEditTransaction(); this.Tool.ShowDimensions = true; this.EditingElement = this.CreateElementOnStartDrag(); this.OnApplyAmbientProperty((SceneNode)this.EditingElement); this.CreateSubTransaction(); if (!this.CanInsert) { return(false); } if (this.EditingElement != null) { this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, this.EditingElement, (IList <BaseFrameworkElement>)null); this.layoutRoundingOverride.SetValue((IEnumerable <SceneElement>) new SceneElement[1] { (SceneElement)this.EditingElement }, 0 != 0); } else { this.CancelEditTransaction(); } } this.SnapDragPosition(dragCurrentPosition); this.UpdateElementPosition(scrollNow); PerformanceUtility.EndPerformanceSequence(PerformanceEvent.ShapeCreateBehaviorOnDrag); } return(true); }
public void AdjustColumn(GridElement grid, int col, double width, bool adjustGridWidth, bool preserveRects) { double computedWidth1 = grid.ColumnDefinitions[col].ComputedWidth; double num = 0.0; grid.CacheComputedColumnWidths(); List <int> widthStarIndices = this.GetWidthStarIndices(grid); List <LayoutCacheRecord> layoutCache = (List <LayoutCacheRecord>)null; if (preserveRects) { layoutCache = this.GetCurrentRects((BaseFrameworkElement)grid); } width = Math.Max(0.0, width); if (col + 1 < grid.ColumnDefinitions.Count) { num = grid.ColumnDefinitions[col + 1].ComputedWidth; width = Math.Min(computedWidth1 + num, width); } else if (!adjustGridWidth) { return; } using (this.DeferTokenForGridDesignMode(grid)) { this.SetColumnWidthCore(grid, col, width); if (!adjustGridWidth) { double width1 = Math.Max(computedWidth1 + num - width, 0.0); this.SetColumnWidthCore(grid, col + 1, width1); grid.ViewModel.Document.OnUpdatedEditTransaction(); grid.ViewModel.DefaultView.UpdateLayout(); if (Tolerances.GreaterThan(grid.ColumnDefinitions[col].ComputedWidth, width)) { width = grid.ColumnDefinitions[col].ComputedWidth; double width2 = Math.Max(computedWidth1 + num - width, 0.0); this.SetColumnWidthCore(grid, col, width); this.SetColumnWidthCore(grid, col + 1, width2); } else if (Tolerances.GreaterThan(grid.ColumnDefinitions[col + 1].ComputedWidth, width1)) { double computedWidth2 = grid.ColumnDefinitions[col + 1].ComputedWidth; width = Math.Max(computedWidth1 + num - computedWidth2, 0.0); this.SetColumnWidthCore(grid, col, width); this.SetColumnWidthCore(grid, col + 1, computedWidth2); } } else { double width1 = this.GetSizeElement((BaseFrameworkElement)grid).GetComputedTightBounds().Width; this.SetGridWidthCore(grid, Math.Max(width1 + width - computedWidth1, 0.0)); grid.ViewModel.Document.OnUpdatedEditTransaction(); grid.ViewModel.DefaultView.UpdateLayout(); if (Tolerances.GreaterThan(grid.ColumnDefinitions[col].ComputedWidth, width)) { width = grid.ColumnDefinitions[col].ComputedWidth; double width2 = Math.Max(width1 + width - computedWidth1, 0.0); this.SetColumnWidthCore(grid, col, width); this.SetGridWidthCore(grid, width2); } } this.NormalizeWidthStars(grid, widthStarIndices); grid.UncacheComputedColumnWidths(); if (!preserveRects) { return; } grid.ViewModel.Document.OnUpdatedEditTransaction(); grid.ViewModel.DefaultView.UpdateLayout(); this.SetCurrentRects((BaseFrameworkElement)grid, layoutCache); } }