public GridExample(View parent, View layoutParent = null, string id = null, Template template = null, bool deferInitialization = false) : base(parent, layoutParent, id, template ?? GridExampleTemplates.Default, deferInitialization) { if (deferInitialization) { return; } // constructing Grid (Grid1) Grid1 = new LayoutGrid(this, this, "Grid1", Grid1Template); Cell00 = new Region(this, Grid1.Content, "Cell00", Cell00Template); Grid1.Cell.SetValue(Cell00, new CellIndex(0, 0)); Cell01 = new Region(this, Grid1.Content, "Cell01", Cell01Template); Grid1.Cell.SetValue(Cell01, new CellIndex(0, 1)); Cell02 = new Region(this, Grid1.Content, "Cell02", Cell02Template); Grid1.Cell.SetValue(Cell02, new CellIndex(0, 2)); Cell10 = new Region(this, Grid1.Content, "Cell10", Cell10Template); Grid1.Cell.SetValue(Cell10, new CellIndex(1, 0)); Cell11 = new Region(this, Grid1.Content, "Cell11", Cell11Template); Grid1.Cell.SetValue(Cell11, new CellIndex(1, 1)); Cell12 = new Region(this, Grid1.Content, "Cell12", Cell12Template); Grid1.Cell.SetValue(Cell12, new CellIndex(1, 2)); Cell20 = new Region(this, Grid1.Content, "Cell20", Cell20Template); Grid1.Cell.SetValue(Cell20, new CellIndex(2, 0)); Cell21 = new Region(this, Grid1.Content, "Cell21", Cell21Template); Grid1.Cell.SetValue(Cell21, new CellIndex(2, 1)); Cell22 = new Region(this, Grid1.Content, "Cell22", Cell22Template); Grid1.Cell.SetValue(Cell22, new CellIndex(2, 2)); GridSplitter1 = new GridSplitter(this, Grid1.Content, "GridSplitter1", GridSplitter1Template); this.AfterInitializeInternal(); }
/// <summary> /// Called after the view has been loaded. /// </summary> protected override void AfterLoad() { base.AfterLoad(); _parentGrid = LayoutParent as LayoutGrid; if (_parentGrid == null) { Debug.LogError(String.Format("#Delight# {0}: GridSplitter must reside within a Grid view.", Name)); return; } // create grid-splitters based on parent grid var cellSpan = _parentGrid.CellSpan.GetValue(this); var cell = _parentGrid.Cell.GetValue(this); int columnCount = _parentGrid.Columns.Count; int rowCount = _parentGrid.Rows.Count; if (cellSpan == null) { cellSpan = new CellIndex(rowCount, columnCount); } if (cell == null) { cell = new CellIndex(0, 0); } var actualCellSpan = new CellIndex(Math.Min(rowCount - cell.Row, cellSpan.Row), Math.Min(columnCount - cell.Column, cellSpan.Column)); int columnSplitterCount = (actualCellSpan.Column - 1) - cell.Column; int rowSplitterCount = (actualCellSpan.Row - 1) - cell.Row; var contentTemplate = ContentTemplates?.FirstOrDefault(); if (SplitMode == SplitMode.Columns || SplitMode == SplitMode.RowsAndColumns) { for (int i = 0; i < columnSplitterCount; ++i) { var gridSplitterHandlerRegion = new Region(_parentGrid); gridSplitterHandlerRegion.Id = String.Format("ColumnGridSplitterRegion{0}", i + 1); gridSplitterHandlerRegion.Load(); gridSplitterHandlerRegion.IsDynamic = true; _parentGrid.Cell.SetValue(gridSplitterHandlerRegion, new CellIndex(cell.Row, cell.Column + i)); _parentGrid.CellSpan.SetValue(gridSplitterHandlerRegion, new CellIndex(cellSpan.Row, 1)); var gridSplitterHandle = new GridSplitterHandle(_parentGrid); gridSplitterHandle.MoveTo(gridSplitterHandlerRegion); gridSplitterHandle.Load(); var thickness = Thickness ?? 10; var interactionThickness = InteractionThickness ?? thickness; var difference = interactionThickness - thickness; if (difference > 0) { gridSplitterHandle.SplitterHandle.Margin = new ElementMargin(difference / 2, 0, difference / 2, 0); } gridSplitterHandle.Width = interactionThickness; gridSplitterHandle.Offset = new ElementMargin(interactionThickness / 2, 0); gridSplitterHandle.Alignment = ElementAlignment.Right; gridSplitterHandle.SplitterHandle.Color = SplitterColor; gridSplitterHandle.SplitterHandle.Sprite = SplitterSprite; gridSplitterHandle.SetSizeOnDragEnded = SetSizeOnDragEnded; gridSplitterHandle.ParentRegion = gridSplitterHandlerRegion; gridSplitterHandle.ParentGrid = _parentGrid; gridSplitterHandle.Index = cell.Column + i; gridSplitterHandle.IsColumnSplitter = true; gridSplitterHandle.BePushy = BePushy; // create content for the handle if (contentTemplate == null) { continue; } var gridSplitterHandleContent = contentTemplate.Activator(ContentTemplateData.Empty); gridSplitterHandleContent.MoveTo(gridSplitterHandle.Content); gridSplitterHandleContent.Load(); } } if (SplitMode == SplitMode.Rows || SplitMode == SplitMode.RowsAndColumns) { for (int i = 0; i < rowSplitterCount; ++i) { var gridSplitterHandlerRegion = new Region(_parentGrid); gridSplitterHandlerRegion.Id = String.Format("RowGridSplitterRegion{0}", i + 1); gridSplitterHandlerRegion.Load(); gridSplitterHandlerRegion.IsDynamic = true; _parentGrid.Cell.SetValue(gridSplitterHandlerRegion, new CellIndex(cell.Row + i, cell.Column)); _parentGrid.CellSpan.SetValue(gridSplitterHandlerRegion, new CellIndex(1, cellSpan.Column)); var gridSplitterHandle = new GridSplitterHandle(_parentGrid); gridSplitterHandle.MoveTo(gridSplitterHandlerRegion); gridSplitterHandle.Load(); var thickness = Thickness ?? 10; var interactionThickness = InteractionThickness ?? thickness; var difference = interactionThickness - thickness; if (difference > 0) { gridSplitterHandle.SplitterHandle.Margin = new ElementMargin(0, difference / 2, 0, difference / 2); } gridSplitterHandle.Height = interactionThickness; gridSplitterHandle.Offset = new ElementMargin(0, interactionThickness / 2); gridSplitterHandle.Alignment = ElementAlignment.Bottom; gridSplitterHandle.SplitterHandle.Color = SplitterColor; gridSplitterHandle.SplitterHandle.Sprite = SplitterSprite; gridSplitterHandle.SetSizeOnDragEnded = SetSizeOnDragEnded; gridSplitterHandle.ParentRegion = gridSplitterHandlerRegion; gridSplitterHandle.ParentGrid = _parentGrid; gridSplitterHandle.Index = cell.Row + i; gridSplitterHandle.IsColumnSplitter = false; gridSplitterHandle.BePushy = BePushy; // create content for the handle if (contentTemplate == null) { continue; } var gridSplitterHandleContent = contentTemplate.Activator(ContentTemplateData.Empty); gridSplitterHandleContent.MoveTo(gridSplitterHandle); gridSplitterHandleContent.Load(); } } }