示例#1
0
 public static void SetAdornedElement(Visual adorner, Visual adorned)
 {
     adorner.SetValue(AdornedElementProperty, adorned);
 }
示例#2
0
        private void UpdateAdornedElement(Visual adorner, Visual adorned)
        {
            var info = adorner.GetValue(s_adornedElementInfoProperty);

            if (info != null)
            {
                info.Subscription.Dispose();

                if (adorned == null)
                {
                    adorner.ClearValue(s_adornedElementInfoProperty);
                }
            }

            if (adorned != null)
            {
                if (info == null)
                {
                    info = new AdornedElementInfo();
                    adorner.SetValue(s_adornedElementInfoProperty, info);
                }

                info.Subscription = _tracker.Track(adorned).Subscribe(x =>
                {
                    info.Bounds = x;
                    InvalidateArrange();
                });
            }
        }
示例#3
0
        public override bool ApplyTemplate()
        {
            if (this.IsInitialized && this.visualChild == null)
            {
                Visual visual = this.Content as Visual;

                if (visual == null && this.Content != null)
                {
                    DataTemplate template = this.ContentTemplate;

                    if (template == null)
                    {
                        DataTemplateKey key = new DataTemplateKey(this.Content.GetType());
                        template = this.TryFindResource(key) as DataTemplate;
                    }

                    if (template != null)
                    {
                        visual = template.CreateVisualTree(this);

                        FrameworkElement fe = visual as FrameworkElement;

                        if (fe != null)
                        {
                            fe.DataContext = this.Content;
                        }
                    }
                    else
                    {
                        visual = new TextBlock
                        {
                            Text = this.Content.ToString(),
                        };
                    }
                }

                if (visual != null)
                {
                    this.visualChild = visual;
                    this.AddVisualChild(this.visualChild);
                    this.OnApplyTemplate();
                    return true;
                }
            }

            return false;
        }
示例#4
0
 public static Visual GetAdornedElement(Visual adorner)
 {
     return adorner.GetValue(AdornedElementProperty);
 }
示例#5
0
 /// <summary>
 /// Gets the transformed bounds of the visual.
 /// </summary>
 /// <param name="visual">The visual.</param>
 /// <returns>The transformed bounds.</returns>
 public static TransformedBounds GetTransformedBounds(Visual visual) => visual.GetValue(TransformedBoundsProperty);
示例#6
0
        private void ContentChanged(object oldValue, object newValue)
        {
            if (oldValue != null)
            {
                this.RemoveLogicalChild(oldValue);
                this.RemoveVisualChild(this.visualChild);
                this.visualChild = null;
            }

            if (newValue != null)
            {
                this.AddLogicalChild(newValue);
            }

            this.ApplyTemplate();
        }
示例#7
0
 /// <summary>
 /// Starts tracking the specified visual.
 /// </summary>
 /// <param name="visual">The visual.</param>
 /// <returns>An observable that returns the tracked bounds.</returns>
 public IObservable<TransformedBounds> Track(Visual visual)
 {
     return visual.GetObservable(TransformedBoundsProperty);
 }
示例#8
0
 internal static void SetTransformedBounds(Visual visual, TransformedBounds bounds)
 {
     visual.SetValue(TransformedBoundsProperty, bounds);
 }
 public PointHitTestResult(Visual visualHit, Point pointHit)
 {
     this.VisualHit = visualHit;
     this.PointHit = pointHit;
 }
示例#10
0
 /// <summary>
 /// Removes a child <see cref="Visual"/> from the visual tree.
 /// </summary>
 /// <param name="child">The child visual.</param>
 protected internal void RemoveVisualChild(Visual child)
 {
     child.VisualParent     = null;
     child.DependencyParent = null;
 }
示例#11
0
        /// <summary>
        /// Adds a child <see cref="Visual"/> to the visual tree.
        /// </summary>
        /// <param name="child">The child visual.</param>
        protected internal void AddVisualChild(Visual child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            DependencyObject oldParent = child.VisualParent;
            child.DependencyParent = this;
            child.VisualParent = this;
            child.OnVisualParentChanged(oldParent);
        }
示例#12
0
 /// <summary>
 /// Removes a child <see cref="Visual"/> from the visual tree.
 /// </summary>
 /// <param name="child">The child visual.</param>
 protected internal void RemoveVisualChild(Visual child)
 {
     child.VisualParent = null;
     child.DependencyParent = null;
 }
示例#13
0
        public sealed override bool ApplyTemplate()
        {
            if (this.IsInitialized && this.child == null)
            {
                if (this.Template == null)
                {
                    this.ApplyTheme();
                }

                if (this.Template != null)
                {
                    this.child = this.Template.CreateVisualTree(this);
                    this.AddVisualChild(this.child);
                    this.OnApplyTemplate();
                    return true;
                }
            }

            return false;
        }