Esempio n. 1
0
        /// <summary>
        /// Creates the <see cref="Child"/> control from the <see cref="Content"/>.
        /// </summary>
        private void CreateChild()
        {
            var old     = Child;
            var content = Content;
            var result  = this.MaterializeDataTemplate(content);

            if (old != null)
            {
                VisualChildren.Remove(old);
            }

            if (result != null)
            {
                if (!(content is IControl))
                {
                    result.DataContext = content;
                }

                Child = result;
                VisualChildren.Add(result);
            }
            else
            {
                Child = null;
            }

            _createdChild = true;
        }
Esempio n. 2
0
        internal void SetVisualLines(ICollection <VisualLine> visualLines)
        {
            foreach (var v in _visuals)
            {
                if (v.VisualLine.IsDisposed)
                {
                    VisualChildren.Remove(v);
                }
            }

            _visuals.Clear();
            foreach (var newLine in visualLines)
            {
                var visual = newLine.Render();
                if (!visual.IsAdded)
                {
                    VisualChildren.Add(visual);
                    visual.IsAdded = true;
                }

                _visuals.Add(visual);
            }

            InvalidateArrange();
        }
Esempio n. 3
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      VisualChildren.Remove(_verticalScrollBar);
      _verticalScrollBar = null;

      base.OnUnload();
    }
Esempio n. 4
0
        /// <inheritdoc/>
        protected override void OnUnload()
        {
            VisualChildren.Remove(_thumb);
            _thumb = null;

            base.OnUnload();
        }
Esempio n. 5
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var old     = Child;
            var content = Content;
            var result  = this.MaterializeDataTemplate(content);

            if (old != null)
            {
                VisualChildren.Remove(old);
            }

            if (result != null)
            {
                if (!(content is IControl))
                {
                    result.DataContext = content;
                }

                Child = result;

                if (result.Parent == null)
                {
                    ((ISetLogicalParent)result).SetParent((ILogical)this.TemplatedParent ?? this);
                }

                VisualChildren.Add(result);
            }
            else
            {
                Child = null;
            }

            _createdChild = true;
        }
Esempio n. 6
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      // Remove scroll bars.
      if (_horizontalScrollBar != null)
      {
        var scrollBarValue = _horizontalScrollBar.Properties.Get<float>(RangeBase.ValuePropertyId);
        var horizontalOffset = Properties.Get<float>(HorizontalOffsetPropertyId);

        scrollBarValue.Changed -= horizontalOffset.Change;
        horizontalOffset.Changed -= scrollBarValue.Change;

        VisualChildren.Remove(_horizontalScrollBar);
        _horizontalScrollBar = null;
      }

      if (_verticalScrollBar != null)
      {
        var scrollBarValue = _verticalScrollBar.Properties.Get<float>(RangeBase.ValuePropertyId);
        var verticalOffset = Properties.Get<float>(VerticalOffsetPropertyId);

        scrollBarValue.Changed -= verticalOffset.Change;
        verticalOffset.Changed -= scrollBarValue.Change;

        VisualChildren.Remove(_verticalScrollBar);
        _verticalScrollBar = null;
      }

      base.OnUnload();
    }
Esempio n. 7
0
        /// <summary>
        /// Synchronizes the logical tree.
        /// </summary>
        /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs" /> instance containing the event data.</param>
        private void SyncLogicalTree(NotifyCollectionChangedEventArgs e)
        {
            // In order to get DataContext and binding to work with the series, axes and annotations
            // we add the items to the logical tree
            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems.OfType <ISetLogicalParent>())
                {
                    item.SetParent(this);
                }
                LogicalChildren.AddRange(e.NewItems.OfType <ILogical>());
                VisualChildren.AddRange(e.NewItems.OfType <IVisual>());
            }

            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems.OfType <ISetLogicalParent>())
                {
                    item.SetParent(null);
                }
                foreach (var item in e.OldItems)
                {
                    LogicalChildren.Remove((ILogical)item);
                    VisualChildren.Remove((IVisual)item);
                }
            }
        }
        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);
            }
        }
Esempio n. 9
0
        /// <inheritdoc/>
        protected override void OnUnload()
        {
            VisualChildren.Remove(_itemsPanel);
            _itemsPanel.Children.Clear();
            _itemsPanel = null;

            base.OnUnload();
        }
Esempio n. 10
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var content  = Content;
            var oldChild = Child;
            var newChild = CreateChild();

            // Remove the old child if we're not recycling it.
            if (oldChild != null && newChild != oldChild)
            {
                VisualChildren.Remove(oldChild);
            }

            // Set the DataContext if the data isn't a control.
            if (!(content is IControl))
            {
                DataContext = content;
            }
            else
            {
                ClearValue(DataContextProperty);
            }

            // Update the Child.
            if (newChild == null)
            {
                Child = null;
            }
            else if (newChild != oldChild)
            {
                ((ISetInheritanceParent)newChild).SetParent(this);

                Child = newChild;

                if (oldChild?.Parent == this)
                {
                    LogicalChildren.Remove(oldChild);
                }

                if (newChild.Parent == null)
                {
                    var templatedLogicalParent = TemplatedParent as ILogical;

                    if (templatedLogicalParent != null)
                    {
                        ((ISetLogicalParent)newChild).SetParent(templatedLogicalParent);
                    }
                    else
                    {
                        LogicalChildren.Add(newChild);
                    }
                }

                VisualChildren.Add(newChild);
            }

            _createdChild = true;
        }
Esempio n. 11
0
 public void RemoveVisualControl(DesignerControl dc)
 {
     if (VisualChildren.Contains(dc))
     {
         VisualChildren.Remove(dc);
     }
     else
     {
         return;
     }
 }
Esempio n. 12
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      // Clean up and remove controls for icon, title and close button.
      if (_icon != null)
      {
        var icon = Properties.Get<Texture2D>(IconPropertyId);
        var imageTexture = _icon.Properties.Get<Texture2D>(Image.TexturePropertyId);
        icon.Changed -= imageTexture.Change;


        var iconSourceRectangle = Properties.Get<Rectangle?>(IconSourceRectanglePropertyId);
        var imageSourceRectangle = _icon.Properties.Get<Rectangle?>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed -= imageSourceRectangle.Change;
#else
        var iconSourceRectangle = Properties.Get<Rectangle>(IconSourceRectanglePropertyId);
        var imageSourceRectangle = _icon.Properties.Get<Rectangle>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed -= imageSourceRectangle.Change;


        VisualChildren.Remove(_icon);
        _icon = null;
      }

      if (_caption != null)
      {
        var title = Properties.Get<string>(TitlePropertyId);
        var captionText = _caption.Properties.Get<string>(TextBlock.TextPropertyId);
        title.Changed -= captionText.Change;

        VisualChildren.Remove(_caption);
        _caption = null;
      }

      if (_closeButton != null)
      {
        _closeButton.Click -= OnCloseButtonClick;
        VisualChildren.Remove(_closeButton);
        _closeButton = null;
      }

      if (_setSpecialCursor && UIService != null)
      {
        UIService.Cursor = null;
        _setSpecialCursor = false;
      }

      Owner = null;
      IsActive = false;
      base.OnUnload();
    }
Esempio n. 13
0
        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            if (visualAdded is Visual)
            {
                VisualChildren.Add(visualAdded as Visual);
            }

            if (visualRemoved is Visual)
            {
                VisualChildren.Remove(visualRemoved as Visual);
            }

            base.OnVisualChildrenChanged(visualAdded, visualRemoved);
        }
Esempio n. 14
0
        /// <inheritdoc/>
        protected override void OnUnload()
        {
            if (_titleTextBlock != null)
            {
                // Disconnect Title and TextBlock.Text.
                var title = Properties.Get <string>(TitlePropertyId);
                var text  = _titleTextBlock.Properties.Get <string>(TextBlock.TextPropertyId);
                title.Changed -= text.Change;

                VisualChildren.Remove(_titleTextBlock);
                _titleTextBlock = null;
            }

            base.OnUnload();
        }
Esempio n. 15
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var content         = Content;
            var oldChild        = Child;
            var newChild        = CreateChild();
            var logicalChildren = Host?.LogicalChildren ?? LogicalChildren;

            // Remove the old child if we're not recycling it.
            if (newChild != oldChild)
            {
                if (oldChild != null)
                {
                    VisualChildren.Remove(oldChild);
                    logicalChildren.Remove(oldChild);
                    ((ISetInheritanceParent)oldChild).SetParent(oldChild.Parent);
                }
            }

            // Set the DataContext if the data isn't a control.
            if (!(content is IControl))
            {
                DataContext = content;
            }
            else
            {
                ClearValue(DataContextProperty);
            }

            // Update the Child.
            if (newChild == null)
            {
                Child = null;
            }
            else if (newChild != oldChild)
            {
                ((ISetInheritanceParent)newChild).SetParent(this);
                Child = newChild;

                if (!logicalChildren.Contains(newChild))
                {
                    logicalChildren.Add(newChild);
                }

                VisualChildren.Add(newChild);
            }

            _createdChild = true;
        }
Esempio n. 16
0
        private void ButtonChanged(AvaloniaPropertyChangedEventArgs e)
        {
            var oldButton = (Button)e.OldValue;
            var newButton = (Button)e.NewValue;

            if (oldButton != null)
            {
                LogicalChildren.Remove(oldButton);
                VisualChildren.Remove(oldButton);
            }

            if (newButton != null)
            {
                LogicalChildren.Add(newButton);
                VisualChildren.Add(newButton);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Called when the <see cref="Content"/> property changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void ContentChanged(AvaloniaPropertyChangedEventArgs e)
        {
            _createdChild = false;

            if (((ILogical)this).IsAttachedToLogicalTree)
            {
                UpdateChild();
            }
            else if (Child != null)
            {
                VisualChildren.Remove(Child);
                LogicalChildren.Remove(Child);
                Child         = null;
                _dataTemplate = null;
            }

            InvalidateMeasure();
        }
Esempio n. 18
0
        /// <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);
            }
        }
Esempio n. 19
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        private void OnChildrenChanged(object sender, CollectionChangedEventArgs <UIControl> eventArgs)
        {
            // Children are also stuffed into the VisualChildren. Both collections should use
            // the same order.

            // Handle moved items.
            if (eventArgs.Action == CollectionChangedAction.Move)
            {
                // Move visual children too.
                VisualChildren.Move(eventArgs.OldItemsIndex, eventArgs.NewItemsIndex);
                return;
            }

            // Handle removed items.
            foreach (var oldItem in eventArgs.OldItems)
            {
                VisualChildren.Remove(oldItem);
            }

            // Handle new items.
            int newItemsIndex = eventArgs.NewItemsIndex;

            if (newItemsIndex == -1)
            {
                // Append items.
                foreach (var newItem in eventArgs.NewItems)
                {
                    VisualChildren.Add(newItem);
                }
            }
            else
            {
                // Make sure that the same order is used in both collections.
                foreach (var newItem in eventArgs.NewItems)
                {
                    VisualChildren.Insert(newItemsIndex, newItem);
                    newItemsIndex++;
                }
            }

            InvalidateMeasure();
        }
Esempio n. 20
0
        /// <summary>
        /// Called when the <see cref="Content"/> was exchanged.
        /// </summary>
        /// <param name="newContent">The new content.</param>
        /// <param name="oldContent">The old content.</param>
        protected virtual void OnContentChanged(UIControl newContent, UIControl oldContent)
        {
            if (oldContent != null)
            {
                VisualChildren.Remove(oldContent);
            }

            if (newContent != null)
            {
                // Apply ContentStyle to Content.
                if (IsLoaded && !string.IsNullOrEmpty(ContentStyle))
                {
                    newContent.Style = ContentStyle;
                }

                VisualChildren.Add(newContent);
            }

            InvalidateMeasure();
        }
Esempio n. 21
0
        private void ThumbChanged(AvaloniaPropertyChangedEventArgs e)
        {
            var oldThumb = (Thumb)e.OldValue;
            var newThumb = (Thumb)e.NewValue;

            if (oldThumb != null)
            {
                oldThumb.DragDelta -= ThumbDragged;

                LogicalChildren.Remove(oldThumb);
                VisualChildren.Remove(oldThumb);
            }

            if (newThumb != null)
            {
                newThumb.DragDelta += ThumbDragged;
                LogicalChildren.Add(newThumb);
                VisualChildren.Add(newThumb);
            }
        }
Esempio n. 22
0
        /// <inheritdoc/>
        protected override void OnUnload()
        {
            // Remove thumb and buttons.
            VisualChildren.Remove(_thumb);
            _thumb = null;

            if (_decrementButton != null)
            {
                var click = _decrementButton.Events.Get <EventArgs>(ButtonBase.ClickEventId);
                click.Event -= OnDecrementButtonClick;
                VisualChildren.Remove(_decrementButton);
                _decrementButton = null;
            }

            if (_incrementButton != null)
            {
                var click = _incrementButton.Events.Get <EventArgs>(ButtonBase.ClickEventId);
                click.Event += OnIncrementButtonClick;
                VisualChildren.Remove(_incrementButton);
                _incrementButton = null;
            }

            base.OnUnload();
        }
Esempio n. 23
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var content  = Content;
            var oldChild = Child;
            var newChild = content as IControl;

            if (content != null && newChild == null)
            {
                // We have content and it isn't a control, so first try to recycle the existing
                // child control to display the new data by querying if the template that created
                // the child can recycle items and that it also matches the new data.
                if (oldChild != null &&
                    _dataTemplate != null &&
                    _dataTemplate.SupportsRecycling &&
                    _dataTemplate.Match(content))
                {
                    newChild = oldChild;
                }
                else
                {
                    // We couldn't recycle an existing control so find a data template for the data
                    // and use it to create a control.
                    _dataTemplate = this.FindDataTemplate(content, ContentTemplate) ?? FuncDataTemplate.Default;
                    newChild      = _dataTemplate.Build(content);

                    // Try to give the new control its own name scope.
                    var controlResult = newChild as Control;

                    if (controlResult != null)
                    {
                        NameScope.SetNameScope(controlResult, new NameScope());
                    }
                }
            }
            else
            {
                _dataTemplate = null;
            }

            // Remove the old child if we're not recycling it.
            if (oldChild != null && newChild != oldChild)
            {
                VisualChildren.Remove(oldChild);
            }

            // Set the DataContext if the data isn't a control.
            if (!(content is IControl))
            {
                DataContext = content;
            }

            // Update the Child.
            if (newChild == null)
            {
                Child = null;
            }
            else if (newChild != oldChild)
            {
                ((ISetInheritanceParent)newChild).SetParent(this);

                Child = newChild;

                if (oldChild?.Parent == this)
                {
                    LogicalChildren.Remove(oldChild);
                }

                if (newChild.Parent == null)
                {
                    var templatedLogicalParent = TemplatedParent as ILogical;

                    if (templatedLogicalParent != null)
                    {
                        ((ISetLogicalParent)newChild).SetParent(templatedLogicalParent);
                    }
                    else
                    {
                        LogicalChildren.Add(newChild);
                    }
                }

                VisualChildren.Add(newChild);
            }

            _createdChild = true;
        }
Esempio n. 24
0
 internal void RemoveChild(IVisual visual)
 {
     VisualChildren.Remove(visual);
 }
Esempio n. 25
0
 public void RemoveChild(Visual v)
 {
     VisualChildren.Remove(v);
 }
Esempio n. 26
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            int firstRow = Cells.GetInitialRow();

            foreach (var cell in Cells.GetVisibleCells())
            {
                double width = AccumulatedColumnWidths[cell.Column.Index + 1] -
                               AccumulatedColumnWidths[cell.Column.Index] - GridControl.VerticalLinesThickness;
                cell.Arrange(new Rect(AccumulatedColumnWidths[cell.Column.Index],
                                      AccumulatedRowHeights[cell.Row - firstRow],
                                      width, cell.DesiredSize.Height));
            }

            UpdateGridLines();
            ScrollBar.Arrange(new Rect(finalSize.Width - ScrollBar.Width, 0.0, ScrollBar.Width, finalSize.Height));
            return(finalSize);

            void UpdateGridLines()
            {
                int lastAccumulatedColumnWidthsIndex = AccumulatedColumnWidths.Count - 1;

                while (ColumnLines.Count > lastAccumulatedColumnWidthsIndex)
                {
                    var columnLine = ColumnLines[ColumnLines.Count - 1];
                    ColumnLines.Remove(columnLine);
                    LogicalChildren.Remove(columnLine);
                    VisualChildren.Remove(columnLine);
                }
                while (lastAccumulatedColumnWidthsIndex > ColumnLines.Count)
                {
                    Line columnLine = new Line();
                    columnLine.Stroke          = GridControl.VerticalLinesBrush;
                    columnLine.StrokeThickness = GridControl.VerticalLinesThickness;
                    ColumnLines.Add(columnLine);
                    LogicalChildren.Add(columnLine);
                    VisualChildren.Add(columnLine);
                }

                int lastAccumulatedRowHeightsIndex = AccumulatedRowHeights.Count(rh => !Double.IsNaN(rh)) - 1;

                while (RowLines.Count > lastAccumulatedRowHeightsIndex)
                {
                    var rowLine = RowLines[RowLines.Count - 1];
                    RowLines.Remove(rowLine);
                    LogicalChildren.Remove(rowLine);
                    VisualChildren.Remove(rowLine);
                }

                while (lastAccumulatedRowHeightsIndex > RowLines.Count)
                {
                    Line rowLine = new Line();
                    rowLine.Stroke          = GridControl.HorizontalLinesBrush;
                    rowLine.StrokeThickness = GridControl.HorizontalLinesThickness;
                    RowLines.Add(rowLine);
                    LogicalChildren.Add(rowLine);
                    VisualChildren.Add(rowLine);
                }

                for (int i = 0; i < RowLines.Count; i++)
                {
                    double y = AccumulatedRowHeights[i + 1] - GridControl.HorizontalLinesThickness / 2.0;
                    RowLines[i].StartPoint = new Point(0.0, y);
                    RowLines[i].EndPoint   = new Point(AccumulatedColumnWidths[lastAccumulatedColumnWidthsIndex], y);
                }

                for (int i = 0; i < ColumnLines.Count; i++)
                {
                    double x = AccumulatedColumnWidths[i + 1] - GridControl.VerticalLinesThickness / 2.0;
                    ColumnLines[i].StartPoint = new Point(x, 0.0);
                    ColumnLines[i].EndPoint   = new Point(x, AccumulatedRowHeights[lastAccumulatedRowHeightsIndex]);
                }

                foreach (var line in RowLines.Concat(ColumnLines))
                {
                    line.InvalidateMeasure();
                    line.Measure(Size.Infinity);
                }
            }
        }