public void RemoveRow(GridElement grid, int index) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitRemoveGridline)) { grid.ViewModel.GridRowSelectionSet.Clear(); grid.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)grid.RowDefinitions[index]); using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); bool isStar1 = grid.RowDefinitions[index - 1].Height.IsStar; bool isStar2 = grid.RowDefinitions[index].Height.IsStar; List <int> heightStarIndices = this.GetHeightStarIndices(grid); grid.CacheComputedRowHeights(); List <double> computedRowHeightCache; int index1; (computedRowHeightCache = grid.ComputedRowHeightCache)[index1 = index - 1] = computedRowHeightCache[index1] + grid.ComputedRowHeightCache[index]; grid.ComputedRowHeightCache.RemoveAt(index); grid.RowDefinitions.RemoveAt(index); if (isStar2) { heightStarIndices.Remove(index); } if (isStar1 || isStar2) { for (int index2 = 0; index2 < heightStarIndices.Count; ++index2) { if (heightStarIndices[index2] > index) { List <int> list; int index3; (list = heightStarIndices)[index3 = index2] = list[index3] - 1; } } this.NormalizeHeightStars(grid, heightStarIndices); } if (!isStar1) { grid.RowDefinitions[index - 1].Height = new GridLength(grid.ComputedRowHeightCache[index - 1]); grid.RowDefinitions[index - 1].ClearValue(RowDefinitionNode.MinHeightProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedRowHeights(); GridLayoutDesigner.ReselectGridToRestoreAdorners(grid); editTransaction.Commit(); } } }
public void AddHorizontalGridline(GridElement grid, double position) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitAddGridline)) { using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); int rowBeforePosition = grid.GetComputedRowBeforePosition(position); double computedPositionOfRow1 = grid.GetComputedPositionOfRow(rowBeforePosition); double computedPositionOfRow2 = grid.GetComputedPositionOfRow(rowBeforePosition + 1); bool flag = grid.RowDefinitions.Count == 0 || grid.RowDefinitions[rowBeforePosition].Height.IsStar; grid.CacheComputedRowHeights(); this.EnsureOneRow(grid); grid.RowDefinitions.Insert(rowBeforePosition + 1, RowDefinitionNode.Factory.Instantiate(grid.ViewModel)); position = Math.Max(position, computedPositionOfRow1); if (position > computedPositionOfRow2) { grid.ComputedRowHeightCache[rowBeforePosition] = computedPositionOfRow2 - computedPositionOfRow1; grid.ComputedRowHeightCache.Insert(rowBeforePosition + 1, position - computedPositionOfRow2); } else { grid.ComputedRowHeightCache[rowBeforePosition] = position - computedPositionOfRow1; grid.ComputedRowHeightCache.Insert(rowBeforePosition + 1, computedPositionOfRow2 - position); } editTransaction.Update(); grid.ViewModel.DefaultView.UpdateLayout(); if (flag) { List <int> heightStarIndices = this.GetHeightStarIndices(grid); this.NormalizeHeightStars(grid, heightStarIndices); } else { grid.RowDefinitions[rowBeforePosition].Height = new GridLength(grid.ComputedRowHeightCache[rowBeforePosition]); grid.RowDefinitions[rowBeforePosition].ClearValue(RowDefinitionNode.MinHeightProperty); grid.RowDefinitions[rowBeforePosition + 1].Height = new GridLength(grid.ComputedRowHeightCache[rowBeforePosition + 1]); grid.RowDefinitions[rowBeforePosition + 1].ClearValue(RowDefinitionNode.MinHeightProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedRowHeights(); editTransaction.Commit(); } } grid.ViewModel.DefaultView.AdornerLayer.InvalidateAdornersStructure((SceneElement)grid); }
protected override sealed bool OnDragEnd(Point dragStartPosition, Point dragEndPosition) { GridElement gridElement = this.ActiveSceneInsertionPoint.SceneElement as GridElement; if (gridElement != null) { gridElement.UncacheComputedColumnWidths(); gridElement.UncacheComputedRowHeights(); } if (this.CanInsert) { this.Tool.ShowDimensions = false; this.FinishElement(); this.ToolBehaviorContext.SnappingEngine.Stop(); this.PreviewInsertionPoint = (ISceneInsertionPoint)null; } if (this.popBehaviorAfterClick) { this.TryPopSelf(); } return(true); }
public void AdjustRow(GridElement grid, int row, double height, bool adjustGridHeight, bool preserveRects) { double computedHeight1 = grid.RowDefinitions[row].ComputedHeight; double num = 0.0; grid.CacheComputedRowHeights(); List <int> heightStarIndices = this.GetHeightStarIndices(grid); List <LayoutCacheRecord> layoutCache = (List <LayoutCacheRecord>)null; if (preserveRects) { layoutCache = this.GetCurrentRects((BaseFrameworkElement)grid); } height = Math.Max(0.0, height); if (row + 1 < grid.RowDefinitions.Count) { num = grid.RowDefinitions[row + 1].ComputedHeight; height = Math.Min(computedHeight1 + num, height); } else if (!adjustGridHeight) { return; } using (this.DeferTokenForGridDesignMode(grid)) { this.SetRowHeightCore(grid, row, height); if (!adjustGridHeight) { double height1 = Math.Max(computedHeight1 + num - height, 0.0); this.SetRowHeightCore(grid, row + 1, height1); grid.ViewModel.Document.OnUpdatedEditTransaction(); grid.ViewModel.DefaultView.UpdateLayout(); if (Tolerances.GreaterThan(grid.RowDefinitions[row].ComputedHeight, height)) { height = grid.RowDefinitions[row].ComputedHeight; double height2 = Math.Max(computedHeight1 + num - height, 0.0); this.SetRowHeightCore(grid, row, height); this.SetRowHeightCore(grid, row + 1, height2); } else if (Tolerances.GreaterThan(grid.RowDefinitions[row + 1].ComputedHeight, height1)) { double computedHeight2 = grid.RowDefinitions[row + 1].ComputedHeight; height = Math.Max(computedHeight1 + num - computedHeight2, 0.0); this.SetRowHeightCore(grid, row, height); this.SetRowHeightCore(grid, row + 1, computedHeight2); } } else { double height1 = this.GetSizeElement((BaseFrameworkElement)grid).GetComputedTightBounds().Height; this.SetGridHeightCore(grid, Math.Max(height1 + height - computedHeight1, 0.0)); grid.ViewModel.Document.OnUpdatedEditTransaction(); grid.ViewModel.DefaultView.UpdateLayout(); if (Tolerances.GreaterThan(grid.RowDefinitions[row].ComputedHeight, height)) { height = grid.RowDefinitions[row].ComputedHeight; double height2 = Math.Max(height1 + height - computedHeight1, 0.0); this.SetRowHeightCore(grid, row, height); this.SetGridHeightCore(grid, height2); } } this.NormalizeHeightStars(grid, heightStarIndices); grid.UncacheComputedRowHeights(); if (!preserveRects) { return; } grid.ViewModel.Document.OnUpdatedEditTransaction(); grid.ViewModel.DefaultView.UpdateLayout(); this.SetCurrentRects((BaseFrameworkElement)grid, layoutCache); } }