// Trường hợp số cell thay đổi private void ReDrawWidthCellsChanged(NumberOfCells newValue) { if (CellList == null) { return; } AdjustCells(newValue); // Thay đổi số Cell RedrawBound(); RedrawDims(this); }
private void AdjustCells(NumberOfCells newCellValue) { //int currentCellsNumber = CellList.Count; int newValue = NumberOfCellsToInt(newCellValue); if (newValue == CellList.Count) { return; } if (newValue > CellList.Count) { // Thêm cells for (int i = CellList.Count; i < newValue; i++) { var cell = Factory.CreatePolyline(Drawing, GetCellDependencies(i)); cell.Name = "Cell" + (i + 1); cell.Style = DefaultStyles.StructureLineStyle; CellList.Add(cell); this.Children.Add(cell); this.Dependencies.Add(cell); cell.OnAddingToCanvas(Drawing.Canvas); cell.Selected = this.Selected; } } else { // Remove cell for (int i = CellList.Count; i > newValue; i--) { RemoveCell(); } } if (CellList == null) { return; } for (int i = 0; i < CellList.Count; i++) { CellList[i].Dependencies = GetCellDependencies(i); CellList[i].RecalculateAndUpdateVisual(); } }
public int NumberOfCellsToInt(NumberOfCells cells) { object o = Convert.ChangeType(cells, cells.GetTypeCode()); return(Convert.ToInt16(o) + 1); }