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); } }
/// <inheritdoc/> public sealed override void ApplyTemplate() { if (!_templateApplied) { VisualChildren.Clear(); if (Template != null) { _templateLog.Verbose("Creating control template"); var child = Template.Build(this); var nameScope = new NameScope(); NameScope.SetNameScope((Control)child, nameScope); // We need to call SetupTemplateControls twice: // - Once before the controls are added to the visual/logical trees so that the // TemplatedParent property is set and names are registered; if // TemplatedParent is not set when the control is added to the logical tree, // then styles with the /template/ selector won't match. // - Once after the controls are added to the logical tree (and thus styled) to // call ApplyTemplate on nested templated controls and register any of our // templated children that appear as children of presenters in these nested // templated child controls. SetupTemplateControls(child, nameScope); VisualChildren.Add(child); ((ISetLogicalParent)child).SetParent(this); SetupTemplateControls(child, nameScope); OnTemplateApplied(new TemplateAppliedEventArgs(nameScope)); } _templateApplied = true; } }
/// <inheritdoc/> public sealed override void ApplyTemplate() { if (!_templateApplied) { if (VisualChildren.Count > 0) { foreach (var child in this.GetTemplateChildren()) { child.SetValue(TemplatedParentProperty, null); } VisualChildren.Clear(); } if (Template != null) { Logger.Verbose(LogArea.Control, this, "Creating control template"); var child = Template.Build(this); var nameScope = new NameScope(); NameScope.SetNameScope((Control)child, nameScope); child.SetValue(TemplatedParentProperty, this); RegisterNames(child, nameScope); ((ISetLogicalParent)child).SetParent(this); VisualChildren.Add(child); OnTemplateApplied(new TemplateAppliedEventArgs(nameScope)); } _templateApplied = true; } }
/// <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); }
/// <inheritdoc/> public sealed override void ApplyTemplate() { var template = Template; var logical = (ILogical)this; // Apply the template if it is not the same as the template already applied - except // for in the case that the template is null and we're not attached to the logical // tree. In that case, the template has probably been cleared because the style setting // the template has been detached, so we want to wait until it's re-attached to the // logical tree as if it's re-attached to the same tree the template will be the same // and we don't need to do anything. if (_appliedTemplate != template && (template != null || logical.IsAttachedToLogicalTree)) { if (VisualChildren.Count > 0) { foreach (var child in this.GetTemplateChildren()) { child.SetValue(TemplatedParentProperty, null); ((ISetLogicalParent)child).SetParent(null); } VisualChildren.Clear(); } if (template != null) { Logger.TryGet(LogEventLevel.Verbose, LogArea.Control)?.Log(this, "Creating control template"); var(child, nameScope) = template.Build(this); ApplyTemplatedParent(child); ((ISetLogicalParent)child).SetParent(this); VisualChildren.Add(child); // Existing code kinda expect to see a NameScope even if it's empty if (nameScope == null) { nameScope = new NameScope(); } var e = new TemplateAppliedEventArgs(nameScope); OnApplyTemplate(e); #pragma warning disable CS0618 // Type or member is obsolete OnTemplateApplied(e); #pragma warning restore CS0618 // Type or member is obsolete RaiseEvent(e); } _appliedTemplate = template; } }
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); }
public Track() { this.GetObservableWithHistory(ThumbProperty).Subscribe(val => { if (val.Item1 != null) { val.Item1.DragDelta -= ThumbDragged; } VisualChildren.Clear(); if (val.Item2 != null) { val.Item2.DragDelta += ThumbDragged; VisualChildren.Add(val.Item2); } }); }
/// <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); }
/// <inheritdoc/> public sealed override void ApplyTemplate() { var template = Template; var logical = (ILogical)this; // Apply the template if it is not the same as the template already applied - except // for in the case that the template is null and we're not attached to the logical // tree. In that case, the template has probably been cleared because the style setting // the template has been detached, so we want to wait until it's re-attached to the // logical tree as if it's re-attached to the same tree the template will be the same // and we don't need to do anything. if (_appliedTemplate != template && (template != null || logical.IsAttachedToLogicalTree)) { if (VisualChildren.Count > 0) { foreach (var child in this.GetTemplateChildren()) { child.SetValue(TemplatedParentProperty, null); ((ISetLogicalParent)child).SetParent(null); } VisualChildren.Clear(); } if (template != null) { Logger.Verbose(LogArea.Control, this, "Creating control template"); var child = template.Build(this); var nameScope = new NameScope(); NameScope.SetNameScope((Control)child, nameScope); ApplyTemplatedParent(child); RegisterNames(child, nameScope); ((ISetLogicalParent)child).SetParent(this); VisualChildren.Add(child); OnTemplateApplied(new TemplateAppliedEventArgs(nameScope)); } _appliedTemplate = template; } }
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); }
/// <inheritdoc/> public sealed override void ApplyTemplate() { if (!_templateApplied) { VisualChildren.Clear(); if (Template != null) { _templateLog.Verbose("Creating control template"); var child = Template.Build(this); var nameScope = new NameScope(); NameScope.SetNameScope((Control)child, nameScope); child.SetValue(TemplatedParentProperty, this); RegisterNames(child, nameScope); ((ISetLogicalParent)child).SetParent(this); VisualChildren.Add(child); OnTemplateApplied(new TemplateAppliedEventArgs(nameScope)); } _templateApplied = true; } }
public void ClearChildren() { VisualChildren.Clear(); }