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

        private void OnChildrenChanged(object sender, CollectionChangedEventArgs <UIControl> eventArgs)
        {
            if (eventArgs.Action == CollectionChangedAction.Move)
            {
                // Move visual children too.
                VisualChildren.Move(eventArgs.OldItemsIndex, eventArgs.NewItemsIndex);
                return;
            }

            // Remove old items from VisualChildren too.
            foreach (var oldItem in eventArgs.OldItems)
            {
                VisualChildren.Remove(oldItem);
            }

            // Add new items to VisualChildren.
            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. 3
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);

            LogicalChildren.Clear();
            VisualChildren.Clear();
            LogicalChildren.Add(Panel);
            VisualChildren.Add(Panel);

            _createdPanel = true;

            INotifyCollectionChanged incc = Items as INotifyCollectionChanged;

            if (incc != null)
            {
                incc.CollectionChanged += ItemsCollectionChanged;
            }

            PanelCreated(Panel);

            ItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
Esempio n. 4
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <inheritdoc/>
        protected override void OnLoad()
        {
            base.OnLoad();

            // Create TextBlock for title
            var titleTextBlockStyle = TitleTextBlockStyle;

            if (!string.IsNullOrEmpty(titleTextBlockStyle)) // No title if no style is specified.
            {
                _titleTextBlock = new TextBlock
                {
                    Name  = "GroupBoxTitle",
                    Style = titleTextBlockStyle,
                    Text  = Title,
                };
                VisualChildren.Add(_titleTextBlock);

                // Connect Title with TextBlock.Text.
                var title = Properties.Get <string>(TitlePropertyId);
                var text  = _titleTextBlock.Properties.Get <string>(TextBlock.TextPropertyId);
                title.Changed += text.Change;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendants.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Attached to visual tree");

            _visualRoot = e.Root;

            if (RenderTransform != null)
            {
                RenderTransform.Changed += RenderTransformChanged;
            }

            OnAttachedToVisualTree(e);
            AttachedToVisualTree?.Invoke(this, e);
            InvalidateVisual();

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnAttachedToVisualTreeCore(e);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendants.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Detached from visual tree");

            _visualRoot = null;

            if (RenderTransform != null)
            {
                RenderTransform.Changed -= RenderTransformChanged;
            }

            OnDetachedFromVisualTree(e);
            DetachedFromVisualTree?.Invoke(this, e);
            e.Root?.Renderer?.AddDirty(this);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnDetachedFromVisualTreeCore(e);
                }
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public override void GenerateSequence(IInlineSequence sequence)
        {
            if (sequence == null)
            {
                throw new ArgumentNullException(nameof(sequence));
            }

            if (Color != null)
            {
                sequence.PushColor(Color.Value);
            }
            if (Background != null)
            {
                sequence.PushBackground(Background.Value);
            }

            if (Text != null)
            {
                sequence.AppendText(Text);
            }
            else
            {
                foreach (InlineElement child in VisualChildren.Cast <InlineElement>())
                {
                    child.GenerateSequence(sequence);
                }
            }

            if (Background != null)
            {
                sequence.PopFormatting();
            }
            if (Color != null)
            {
                sequence.PopFormatting();
            }
        }
Esempio n. 9
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. 10
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;
            }
        }
Esempio n. 11
0
 public void AddChildren(IEnumerable <Visual> v)
 {
     VisualChildren.AddRange(v);
 }
Esempio n. 12
0
 public void RemoveChild(Visual v)
 {
     VisualChildren.Remove(v);
 }
 protected override void OnTemplateChildChanged()
 {
     // move AdornerLayer to the top
     SetVisualChildIndex(AdornerLayer, VisualChildren.Count() - 1);
 }
Esempio n. 14
0
 public void AddChild(Visual v)
 {
     VisualChildren.Add(v);
 }
Esempio n. 15
0
 private void BringToFront(Visual child)
 {
     SetVisualChildIndex(child, VisualChildren.Count() - 1);
 }
Esempio n. 16
0
 protected override bool HitTestOverride(Point position)
 {
     // receive a click if there is a non "StaysOpen" child opened
     return(VisualChildren.Any(child => GetIsOpen(child) && !GetStaysOpen(child)));
 }
Esempio n. 17
0
 public void AddVisualChild(IVisual visual)
 {
     VisualChildren.Add(visual);
 }
Esempio n. 18
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);
                }
            }
        }
Esempio n. 19
0
    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // Create icon.
      var iconStyle = IconStyle;
      if (!string.IsNullOrEmpty(iconStyle))
      {
        _icon = new Image
        {
          Name = "WindowIcon",
          Style = iconStyle,
          Texture = Icon,
          SourceRectangle = IconSourceRectangle,
        };
        VisualChildren.Add(_icon);

        // Connect Icon property with Image.Texture.
        GameProperty<Texture2D> icon = Properties.Get<Texture2D>(IconPropertyId);
        GameProperty<Texture2D> imageTexture = _icon.Properties.Get<Texture2D>(Image.TexturePropertyId);
        icon.Changed += imageTexture.Change;


        // Connect IconSourceRectangle property with Image.SourceRectangle.
        GameProperty<Rectangle?> iconSourceRectangle = Properties.Get<Rectangle?>(IconSourceRectanglePropertyId);
        GameProperty<Rectangle?> imageSourceRectangle = _icon.Properties.Get<Rectangle?>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed += imageSourceRectangle.Change;
#else
        // Connect IconSourceRectangle property with Image.SourceRectangle.
        GameProperty<Rectangle> iconSourceRectangle = Properties.Get<Rectangle>(IconSourceRectanglePropertyId);
        GameProperty<Rectangle> imageSourceRectangle = _icon.Properties.Get<Rectangle>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed += imageSourceRectangle.Change;

      }

      // Create text block for title.
      var titleTextBlockStyle = TitleTextBlockStyle;
      if (!string.IsNullOrEmpty(titleTextBlockStyle))
      {
        _caption = new TextBlock
        {
          Name = "WindowTitle",
          Style = titleTextBlockStyle,
          Text = Title,
        };
        VisualChildren.Add(_caption);

        // Connect Title property with TextBlock.Text.
        GameProperty<string> title = Properties.Get<string>(TitlePropertyId);
        GameProperty<string> captionText = _caption.Properties.Get<string>(TextBlock.TextPropertyId);
        title.Changed += captionText.Change;
      }

      // Create Close button.
      var closeButtonStyle = CloseButtonStyle;
      if (!string.IsNullOrEmpty(closeButtonStyle))
      {
        _closeButton = new Button
        {
          Name = "CloseButton",
          Style = closeButtonStyle,
          Focusable = false,
        };
        VisualChildren.Add(_closeButton);

        _closeButton.Click += OnCloseButtonClick;
      }
    }
Esempio n. 20
0
 public bool HitTest(Point point) => VisualChildren.HitTestCustom(point);
 partial void ExtraInitialize()
 {
     VisualChildren.Add(WebView);
 }
Esempio n. 22
0
 internal void RemoveChild(IVisual visual)
 {
     VisualChildren.Remove(visual);
 }
Esempio n. 23
0
 partial void ExtraInitialize()
 {
     AttachedToVisualTree += OnAttachedToVisualTree;
     VisualChildren.Add(View);
 }
Esempio n. 24
0
 public void ClearChildren()
 {
     VisualChildren.Clear();
 }
Esempio n. 25
0
 partial void ExtraInitialize()
 {
     VisualChildren.Add(chromium);
 }
Esempio n. 26
0
 internal void AddChild(IVisual visual)
 {
     VisualChildren.Add(visual);
     InvalidateArrange();
 }
Esempio n. 27
0
 protected override void OnTemplateChildChanged()
 {
     SetVisualChildIndex(AdornerLayer, VisualChildren.Count() - 2);
     SetVisualChildIndex(PopupLayer, VisualChildren.Count() - 1);
 }
Esempio n. 28
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. 29
0
 /// <summary>
 /// Gets the child offset, related to parent.
 /// </summary>
 /// <param name="childIndex">Index of the child.</param>
 /// <returns></returns>
 public int GetChildOffset(int childIndex) => VisualChildren.Take(childIndex).Sum(c => c.Size);