Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <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;
            }
        }
Exemplo n.º 3
0
        /// <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;
            }
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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;
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 9
0
        /// <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;
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        /// <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));
        }
Exemplo n.º 12
0
        /// <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();
        }
Exemplo n.º 13
0
        /// <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);
        }
Exemplo n.º 14
0
        /// <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;
            }
        }
Exemplo n.º 15
0
 public void ClearChildren()
 {
     VisualChildren.Clear();
 }