public void RecreateCells() { LogicalChildren.Clear(); VisualChildren.Clear(); Cells = new CellsCollection(GridControl.Columns, AddCellAction, RemoveCellAction); LogicalChildren.Add(ScrollBar); VisualChildren.Add(ScrollBar); //TODO recalculate with viewport ScrollBar.Maximum = GridControl.Controller.Count; void AddCellAction(Cell cell) { //cell.PointerReleased += CellOnPointerReleased; LogicalChildren.Add(cell); VisualChildren.Add(cell); } void RemoveCellAction(Cell cell) { //cell.PointerReleased -= CellOnPointerReleased; LogicalChildren.Remove(cell); VisualChildren.Remove(cell); } }
/// <summary> /// Called when the <see cref="Children"/> collection changes. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> private void ChildrenChanged(object sender, NotifyCollectionChangedEventArgs e) { List <Control> controls; // TODO: Handle Replace. switch (e.Action) { case NotifyCollectionChangedAction.Add: controls = e.NewItems.OfType <Control>().ToList(); SetLogicalParent(controls); AddVisualChildren(e.NewItems.OfType <Visual>()); LogicalChildren.InsertRange(e.NewStartingIndex, controls); break; case NotifyCollectionChangedAction.Remove: controls = e.OldItems.OfType <Control>().ToList(); ClearLogicalParent(e.OldItems.OfType <Control>()); LogicalChildren.RemoveAll(controls); RemoveVisualChildren(e.OldItems.OfType <Visual>()); break; case NotifyCollectionChangedAction.Reset: controls = e.OldItems.OfType <Control>().ToList(); ClearLogicalParent(controls); LogicalChildren.Clear(); ClearVisualChildren(); AddVisualChildren(_children); break; } InvalidateMeasure(); }
/// <summary> /// Called when the <see cref="Child"/> property changes. /// </summary> /// <param name="e">The event args.</param> private void ChildChanged(AvaloniaPropertyChangedEventArgs e) { LogicalChildren.Clear(); ((ISetLogicalParent)e.OldValue)?.SetParent(null); if (e.NewValue != null) { ((ISetLogicalParent)e.NewValue).SetParent(this); LogicalChildren.Add((ILogical)e.NewValue); } }
/// <summary> /// Creates the <see cref="Panel"/>. /// </summary> private void CreatePanel() { Panel = ItemsPanel.Build(); Panel.SetValue(TemplatedParentProperty, TemplatedParent); LogicalChildren.Clear(); VisualChildren.Clear(); LogicalChildren.Add(Panel); VisualChildren.Add(Panel); _createdPanel = true; var task = MoveToPage(-1, SelectedIndex); }
public void RecreateContent() { LogicalChildren.Clear(); VisualChildren.Clear(); GridBorderLines.Clear(); for (int i = 0; i < 4; i++) { var line = new Line() { Stroke = GridControl.BorderBrush, StrokeThickness = GridControl.BorderThickness }; GridBorderLines.Add(line); LogicalChildren.Add(line); VisualChildren.Add(line); } ColumnHeaders.Clear(); ColumnHeaderLines.Clear(); for (int i = 0; i < GridControl.Columns.Count; i++) { GridControl.Columns[i].Index = i; var columnHeader = GridControl.Columns[i].CreateColumnHeader(); ColumnHeaders.Add(columnHeader); LogicalChildren.Add(columnHeader); VisualChildren.Add(columnHeader); var line = new Line() { Stroke = GridControl.VerticalLinesBrush, StrokeThickness = GridControl.VerticalLinesThickness }; ColumnHeaderLines.Add(line); LogicalChildren.Add(line); VisualChildren.Add(line); } HorizontalHeaderLine = new Line() { Stroke = GridControl.HorizontalLinesBrush, StrokeThickness = GridControl.HorizontalLinesThickness }; LogicalChildren.Add(HorizontalHeaderLine); VisualChildren.Add(HorizontalHeaderLine); CellsPanel.RecreateCells(); LogicalChildren.Add(CellsPanel); VisualChildren.Add(CellsPanel); }
/// <summary> /// Called when the <see cref="Child"/> property changes. /// </summary> /// <param name="e">The event args.</param> private void ChildChanged(AvaloniaPropertyChangedEventArgs e) { var oldChild = (Control)e.OldValue; var newChild = (Control)e.NewValue; if (oldChild != null) { ((ISetLogicalParent)oldChild).SetParent(null); LogicalChildren.Clear(); VisualChildren.Remove(oldChild); } if (newChild != null) { ((ISetLogicalParent)newChild).SetParent(this); VisualChildren.Add(newChild); LogicalChildren.Add(newChild); } }
/// <summary> /// Creates the <see cref="Panel"/> when <see cref="ApplyTemplate"/> is called for the first /// time. /// </summary> private void CreatePanel() { Panel = ItemsPanel.Build(); Panel.SetValue(TemplatedParentProperty, TemplatedParent); LogicalChildren.Clear(); VisualChildren.Clear(); LogicalChildren.Add(Panel); VisualChildren.Add(Panel); _createdPanel = true; if (!IsHosted && _itemsSubscription == null && Items is INotifyCollectionChanged incc) { _itemsSubscription = incc.WeakSubscribe(ItemsCollectionChanged); } PanelCreated(Panel); }
private void ThumbChanged(AvaloniaPropertyChangedEventArgs e) { var oldThumb = (Thumb)e.OldValue; var newThumb = (Thumb)e.NewValue; if (oldThumb != null) { oldThumb.DragDelta -= ThumbDragged; } LogicalChildren.Clear(); VisualChildren.Clear(); if (newThumb != null) { newThumb.DragDelta += ThumbDragged; LogicalChildren.Add(newThumb); VisualChildren.Add(newThumb); } }
/// <summary> /// Creates the <see cref="Panel"/> when <see cref="ApplyTemplate"/> is called for the first /// time. /// </summary> protected virtual void CreatePanel() { Panel = ItemsPanel.Build(); Panel.SetValue(TemplatedParentProperty, TemplatedParent); LogicalChildren.Clear(); VisualChildren.Clear(); LogicalChildren.Add(Panel); VisualChildren.Add(Panel); _createdPanel = true; INotifyCollectionChanged incc = Items as INotifyCollectionChanged; if (incc != null) { incc.CollectionChanged += ItemsCollectionChanged; } ItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
/// <summary> /// Called when the <see cref="Children"/> collection changes. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> private void ChildrenChanged(object sender, NotifyCollectionChangedEventArgs e) { List <Control> controls; switch (e.Action) { case NotifyCollectionChangedAction.Add: controls = e.NewItems.OfType <Control>().ToList(); LogicalChildren.InsertRange(e.NewStartingIndex, controls); VisualChildren.AddRange(e.NewItems.OfType <Visual>()); break; case NotifyCollectionChangedAction.Remove: controls = e.OldItems.OfType <Control>().ToList(); LogicalChildren.RemoveAll(controls); VisualChildren.RemoveAll(e.OldItems.OfType <Visual>()); break; case NotifyCollectionChangedAction.Replace: for (var i = 0; i < e.OldItems.Count; ++i) { var index = i + e.OldStartingIndex; var child = (IControl)e.NewItems[i]; LogicalChildren[index] = child; VisualChildren[index] = child; } break; case NotifyCollectionChangedAction.Reset: controls = e.OldItems.OfType <Control>().ToList(); LogicalChildren.Clear(); VisualChildren.Clear(); VisualChildren.AddRange(_children); break; } InvalidateMeasure(); }
/// <summary> /// Creates the <see cref="Panel"/> when <see cref="ApplyTemplate"/> is called for the first /// time. /// </summary> private void CreatePanel() { Panel = ItemsPanel.Build(); Panel.SetValue(TemplatedParentProperty, TemplatedParent); if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty)) { KeyboardNavigation.SetDirectionalNavigation( (InputElement)Panel, KeyboardNavigationMode.Contained); } LogicalChildren.Clear(); VisualChildren.Clear(); LogicalChildren.Add(Panel); VisualChildren.Add(Panel); KeyboardNavigation.SetTabNavigation( (InputElement)Panel, KeyboardNavigation.GetTabNavigation(this)); _createdPanel = true; CreateItemsAndListenForChanges(Items); }