// Used to interleave specified row dimensions with automatic rows added to use // underlying Grid layout for main arrange of UniformGrid. internal void SetupRowDefinitions(int rows) { // Mark initial definitions so we don't erase them. foreach (var rd in RowDefinitions) { if (GetAutoLayout(rd) == null) { SetAutoLayout(rd, false); } } // Remove non-autolayout rows we've added and then add them in the right spots. if (rows != RowDefinitions.Count) { for (int r = RowDefinitions.Count - 1; r >= 0; r--) { if (GetAutoLayout(RowDefinitions[r]) == true) { RowDefinitions.RemoveAt(r); } } for (int r = this.RowDefinitions.Count; r < rows; r++) { var rd = new RowDefinition(); SetAutoLayout(rd, true); this.RowDefinitions.Insert(r, rd); } } }
protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved) { var added = visualAdded != null; var removed = visualRemoved != null; if (added != removed) { if (Orientation == Orientation.Horizontal) { if (removed) { ColumnDefinitions.RemoveAt(ColumnDefinitions.Count - 1); } else { ColumnDefinitions.Add(new ColumnDefinition()); visualAdded.SetValue(Grid.ColumnProperty, ColumnDefinitions.Count - 1); } } else { if (removed) { RowDefinitions.RemoveAt(RowDefinitions.Count - 1); } else { RowDefinitions.Add(new RowDefinition()); visualAdded.SetValue(Grid.RowProperty, RowDefinitions.Count - 1); } } } base.OnVisualChildrenChanged(visualAdded, visualRemoved); }
private void updateRowDefinitions() { while (RowDefinitions.Count < RowCount) { var definition = new RowDefinition(); definition.Height = new GridLength(1, GridUnitType.Star); RowDefinitions.Add(definition); } while (RowDefinitions.Count > RowCount) { RowDefinitions.RemoveAt(RowDefinitions.Count - 1); } }
private void RemoveFooter() { if (FooterRow > -1 && Rows[FooterRow] != null) { foreach (var c in Rows[FooterRow]) { Children.Remove(c); } Rows.RemoveAt(FooterRow); RowDefinitions.RemoveAt(FooterRow); FooterRow = -1; } }
private void RemoveFooter() { if (FooterRow > -1 && Rows[FooterRow] != null) { foreach (var c in Rows[FooterRow]) { c.BindingContext = null; Children.Remove(c); } Rows.RemoveAt(FooterRow); if (RowDefinitions.Count > FooterRow) { RowDefinitions.RemoveAt(FooterRow); } FooterRow = -1; } }
private void OnRowsCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (_viewModel == null) { return; } // remove extra children while (Children.Count > _viewModel.Rows.Count) { var child = Children[Children.Count - 1]; if (child is FrameworkElement) { (child as FrameworkElement).DataContext = null; } // remote the extra child and its row definition Children.Remove(child); RowDefinitions[RowDefinitions.Count - 1].ClearValue(RowDefinition.HeightProperty); RowDefinitions.RemoveAt(RowDefinitions.Count - 1); } // add enough row controls to match the number of row view models we have while (Children.Count < _viewModel.Rows.Count) { Children.Add(new OnScreenKeyboardRow(_onScreenKeyboard)); RowDefinitions.Add(new RowDefinition()); } // now that we have an exact number of rows, // matching the exact number of controls, // update all the data contexts foreach (var row in _viewModel.Rows) { var index = _viewModel.Rows.IndexOf(row); var keyboardSectionRow = ((OnScreenKeyboardRow)Children[index]); keyboardSectionRow.DataContext = row; SetRow(keyboardSectionRow, index); RowDefinitions[index].SetBinding(RowDefinition.HeightProperty, new Binding("RowHeight") { Source = row }); } }
public BindingPinView(PinData pindata) { InitializeComponent(); switch (pindata.BindingPinType) { case BindingPinType.Normal: SetActive(pindata.IsActive, pindata.BindingPinCardType); HeightRequest = 90; RootInfoFrame.IsVisible = false; SetRow(frame, 0); RowDefinitions.RemoveAt(0); break; case BindingPinType.Info: SetActive(pindata.IsActive, pindata.BindingPinCardType); InfoText.Text = pindata.Cost.ToString(); break; default: break; } }
public void Undock(IDockLayout child) { int index = m_children.IndexOf(child); if (Orientation == Orientation.Horizontal) { ColumnDefinitions.RemoveAt(index * 2); Children.RemoveAt(index * 2); if (m_children.Count > 1) { ColumnDefinitions.RemoveAt(index * 2 + (index == 0 ? 0 : -1)); Children.RemoveAt(index * 2 + (index == 0 ? 0 : -1)); for (int i = 0; i < Children.Count; i++) { Grid.SetColumn(Children[i], i); } } } else { RowDefinitions.RemoveAt(index * 2); Children.RemoveAt(index * 2); if (m_children.Count > 1) { RowDefinitions.RemoveAt(index * 2 + (index == 0 ? 0 : -1)); Children.RemoveAt(index * 2 + (index == 0 ? 0 : -1)); for (int i = 0; i < Children.Count; i++) { Grid.SetRow(Children[i], i); } } } m_children.RemoveAt(index); Root.CheckConsistency(); }
private void ResizeGrid() { if (_keys == null) { Reset(); return; } // Make sure there's the right number of rows var rowCount = _keys.Max(x => x.GridRow) + 1; for (var rowsToAdd = rowCount - RowDefinitions.Count; rowsToAdd > 0; rowsToAdd--) { // Add the extra Row RowDefinitions.Add(new RowDefinition()); } for (var rowsToRemove = RowDefinitions.Count - rowCount; rowsToRemove > 0; rowsToRemove--) { // Remove the extra Row RowDefinitions.RemoveAt(0); } // Make sure there's the right number of cols var colCount = _keys.Max(x => x.GridColumn) + 1; for (var colsToAdd = colCount - ColumnDefinitions.Count; colsToAdd > 0; colsToAdd--) { // Add the extra Column ColumnDefinitions.Add(new ColumnDefinition()); } for (var colsToRemove = ColumnDefinitions.Count - colCount; colsToRemove > 0; colsToRemove--) { // Remove the extra Column ColumnDefinitions.RemoveAt(0); } }
private void OnSplitView(object sender, ExecutedRoutedEventArgs e) { if (secondaryTextEditor == null) { // create secondary editor var rowDefinition = new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight }; if (RowDefinitions.Count < 3) { RowDefinitions.Add(rowDefinition); } else { RowDefinitions[2] = rowDefinition; } secondaryTextEditor = CreateTextEditor(); //secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor)); //Debug.Assert(primaryTextEditorAdapter != null); secondaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding(TextEditor.DocumentProperty.Name) { Source = primaryTextEditor }); secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty, new Binding(TextEditor.IsReadOnlyProperty.Name) { Source = primaryTextEditor }); secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting; //secondaryTextEditor.UpdateCustomizedHighlighting(); gridSplitter = new GridSplitter { Height = 4, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top }; SetRow(gridSplitter, 2); Children.Add(gridSplitter); secondaryTextEditor.Margin = new Thickness(0, 4, 0, 0); SetRow(secondaryTextEditor, 2); Children.Add(secondaryTextEditor); //secondaryTextEditorAdapter.FileNameChanged(); //FetchParseInformation(); } else { // remove secondary editor Children.Remove(secondaryTextEditor); Children.Remove(gridSplitter); //secondaryTextEditorAdapter.Language.Detach(); DisposeTextEditor(secondaryTextEditor); secondaryTextEditor = null; //secondaryTextEditorAdapter = null; gridSplitter = null; RowDefinitions.RemoveAt(RowDefinitions.Count - 1); ActiveTextEditor = primaryTextEditor; } }
/// <summary> /// Will merge itself with given grid. Basicly it takes child grid, removes that grid, and all /// children of removed grid will be added to this grid. The child grid must have same orientation /// or maximum of 1 child. /// </summary> /// <param name="grid">Grid to merge with</param> internal void MergeWith(GridLayout grid) { // get the index of the grid to merge with (it is child of this grid) int index = m_children.IndexOf(grid); double totalValue = 0; int indexOffset = 0; if (Orientation == Orientation.Horizontal) { // get the column definition of child grid ColumnDefinition oldColumnDef = ColumnDefinitions[index * 2]; // count the sum of columns widths of childs children foreach (IDockLayout newLayout in grid.Layouts) { FrameworkElement element = (FrameworkElement)newLayout; int columnIndex = Grid.GetColumn(element); ColumnDefinition layoutColumnDef = grid.ColumnDefinitions[columnIndex]; totalValue += layoutColumnDef.Width.Value; } // remove the child from our list, from view children adn from column definitions m_children.RemoveAt(index); Children.RemoveAt(index * 2); ColumnDefinitions.RemoveAt(index * 2); // move all childs children to this grid and create column definitions for each of them foreach (IDockLayout newLayout in grid.Layouts) { FrameworkElement element = (FrameworkElement)newLayout; int columnIndex = Grid.GetColumn(element); ColumnDefinition layoutColumnDef = grid.ColumnDefinitions[columnIndex]; double newValue = oldColumnDef.Width.Value * layoutColumnDef.Width.Value / totalValue; ColumnDefinition newColumnDef = NewColumnDefinition(new GridLength(newValue, GridUnitType.Star), m_minGridSize.Width); grid.Children.Remove(element); ColumnDefinitions.Insert((index + indexOffset) * 2, newColumnDef); Children.Insert((index + indexOffset) * 2, element); m_children.Insert(index + indexOffset, newLayout); if (indexOffset < grid.Layouts.Count - 1) { // if we move more than one child, then we need to add new splitters too GridSplitter splitter = NewGridSplitter(Orientation.Horizontal); ColumnDefinitions.Insert((index + indexOffset) * 2 + 1, NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); Children.Insert((index + indexOffset) * 2 + 1, splitter); } indexOffset++; } // set the association of column indexes for (int i = 0; i < Children.Count; i++) { Grid.SetColumn(Children[i], i); } } else { // get the row definition of child grid RowDefinition oldRowDef = RowDefinitions[index * 2]; // count the sum of row heights of childs children foreach (IDockLayout newLayout in grid.Layouts) { FrameworkElement element = (FrameworkElement)newLayout; int RowIndex = Grid.GetRow(element); RowDefinition layoutRowDef = grid.RowDefinitions[RowIndex]; totalValue += layoutRowDef.Height.Value; } // remove the child from our list, from view children adn from row definitions m_children.RemoveAt(index); Children.RemoveAt(index * 2); RowDefinitions.RemoveAt(index * 2); // move all childs children to this grid and create row definitions for each of them foreach (IDockLayout newLayout in grid.Layouts) { FrameworkElement element = (FrameworkElement)newLayout; int RowIndex = Grid.GetRow(element); RowDefinition layoutRowDef = grid.RowDefinitions[RowIndex]; double newValue = oldRowDef.Height.Value * layoutRowDef.Height.Value / totalValue; RowDefinition newRowDef = NewRowDefinition(new GridLength(newValue, GridUnitType.Star), m_minGridSize.Height); grid.Children.Remove(element); RowDefinitions.Insert((index + indexOffset) * 2, newRowDef); Children.Insert((index + indexOffset) * 2, element); m_children.Insert(index + indexOffset, newLayout); if (indexOffset < grid.Layouts.Count - 1) { // if we move more than one child, then we need to add new splitters too GridSplitter splitter = NewGridSplitter(Orientation.Vertical); RowDefinitions.Insert((index + indexOffset) * 2 + 1, NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); Children.Insert((index + indexOffset) * 2 + 1, splitter); } indexOffset++; } // set the association of row indexes for (int i = 0; i < Children.Count; i++) { Grid.SetRow(Children[i], i); } } }
/// <summary> /// Delete compoenent from the rung /// </summary> /// <param name="component">Component to be deleted</param> public RungUI Remove(ComponentUIBase component) { ComponentGridPosition _component = _Components.Where(x => x.Component == component).First(); if (_LogicalRung.Components.Where(x => x.LeftLide == component.LogicComponent.LeftLide && x.RightLide == component.LogicComponent.RightLide).Count() > 1) { foreach (ComponentGridPosition item in GetAllBetween(component.LogicComponent.LeftLide, component.LogicComponent.RightLide).Where(x => x.Row > _component.Row)) { item.SetPossition(item.Row - 1, item.Column); } } else { IEnumerable <ComponentGridPosition> RR = _Components.Where(x => x.Component.LogicComponent.RightLide == component.LogicComponent.RightLide && x != _component); if (RR.Count() > 0) { IEnumerable <ComponentGridPosition> column_components = _Components.Where(x => x.Column == _component.Column); if (column_components.Count() == 1) { foreach (ComponentGridPosition item in _Components.Where(x => x.Column > _component.Column)) { item.SetPossition(item.Row, item.Column - 1); } } else { foreach (ComponentGridPosition item in GetAllBetween(component.LogicComponent.LeftLide, component.LogicComponent.RightLide).Where(x => x.Row > _component.Row)) { item.SetPossition(item.Row - 1, item.Column); } } } else { foreach (ComponentGridPosition item in _Components.Where(x => x.Component.LogicComponent.LeftLide == component.LogicComponent.RightLide)) { item.SetPossition(item.Row, item.Column - 1); } } } _Components.Remove(_component); _LogicalRung.Remove(component.LogicComponent); Children.Remove(component); var row = RowDefinitions.Where(x => _Components.Where(y => (y.Row == RowDefinitions.IndexOf(x))).Count() == 0); if (row.Count() != 0) { int row_index = RowDefinitions.IndexOf(row.First()); foreach (ComponentGridPosition item in _Components.Where(x => x.Row > row_index)) { item.SetPossition(item.Row - 1, item.Column); } RowDefinitions.RemoveAt(row_index); } var column = ColumnDefinitions.Where(x => _Components.Where(y => (y.Column == ColumnDefinitions.IndexOf(x))).Count() == 0); if (column.Count() != 0) { int column_index = ColumnDefinitions.IndexOf(column.First()); if (_component.Column >= ColumnDefinitions.Count - _OutputBlockLegth) { _OutputBlockLegth--; } foreach (ComponentGridPosition item in _Components.Where(x => x.Column > column_index)) { item.SetPossition(item.Row, item.Column - 1); } ColumnDefinitions.RemoveAt(column_index); } return(this); }