예제 #1
0
        /// <summary>
        /// Create a <see cref="VisualBrushDragAdorner"/> that renders a rectangle with fills set to a visual brush of the adorned element.
        /// </summary>
        /// <param name="adornedElement">The drag source.</param>
        /// <returns>
        /// A <see cref="VisualBrushDragAdorner"/> that should be disposed when the drag operation ends.
        /// Disposing it removes subscriptions and removes the adorner.
        /// </returns>
        public static VisualBrushDragAdorner CreateVisualBrushAdorner(FrameworkElement adornedElement)
        {
            var adorner = new VisualBrushDragAdorner(adornedElement);

            AdornerService.Show(adorner);
            return(adorner);
        }
예제 #2
0
        private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = (UIElement)d;

            if (Equals(e.NewValue, true))
            {
                var adorner = element.GetAdorner();
                if (adorner == null)
                {
                    adorner = TemplatedAdorner.Create(element, (ControlTemplate)element.GetValue(TemplateProperty));
                    element.SetAdorner(adorner);
                }

                AdornerService.Show(adorner);
            }
            else
            {
                var adorner = element.GetAdorner();
                if (adorner != null)
                {
                    AdornerService.Remove(adorner);
                }

                element.ClearValue(AdornerProperty);
            }
        }
예제 #3
0
        private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = (UIElement)d;

            if (Equals(e.NewValue, true))
            {
                var adorner = element.GetAdorner();
                if (adorner == null)
                {
                    var adornedElement = element is Window
                        ? element.FirstOrDefaultRecursiveVisualChild <AdornerDecorator>()?.Child
                        : element;

                    adorner = new ContentAdorner(adornedElement);
                    element.SetAdorner(adorner);
                }

                SetIfNotNull(d, ContentProperty, adorner, ContentAdorner.ContentProperty);
                SetIfNotNull(d, ContentTemplateProperty, adorner, ContentAdorner.ContentTemplateProperty);
                SetIfNotNull(d, ContentTemplateSelectorProperty, adorner, ContentAdorner.ContentTemplateSelectorProperty);
                SetIfNotNull(d, ContentPresenterStyleProperty, adorner, ContentAdorner.ContentPresenterStyleProperty);
                AdornerService.Show(adorner);
            }
            else
            {
                var adorner = element.GetAdorner();
                if (adorner != null)
                {
                    AdornerService.Remove(adorner);
                }

                element.ClearValue(AdornerProperty);
            }
        }
예제 #4
0
        private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = (UIElement)d;

            if (Equals(e.NewValue, true))
            {
                var adorner = element.GetAdorner();
                if (adorner == null)
                {
                    adorner = new ContentAdorner(element);
                    element.SetAdorner(adorner);
                }

                SetIfNotNull(d, ContentProperty, adorner, ContentAdorner.ContentProperty);
                SetIfNotNull(d, ContentTemplateProperty, adorner, ContentAdorner.ContentTemplateProperty);
                SetIfNotNull(d, ContentTemplateSelectorProperty, adorner, ContentAdorner.ContentTemplateSelectorProperty);
                SetIfNotNull(d, ContentPresenterStyleProperty, adorner, ContentAdorner.ContentPresenterStyleProperty);
                AdornerService.Show(adorner);
            }
            else
            {
                var adorner = element.GetAdorner();
                if (adorner != null)
                {
                    AdornerService.Remove(adorner);
                }

                element.ClearValue(AdornerProperty);
            }
        }
예제 #5
0
        private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var adornedElement = (Control)d;

            if (Equals(e.NewValue, true))
            {
                var adorner = adornedElement.GetAdorner();
                if (adorner == null)
                {
                    adorner = new WatermarkAdorner(adornedElement);
                    adornedElement.SetAdorner(adorner);
                    var textStyle = adornedElement.GetTextStyle();
                    if (textStyle != null)
                    {
                        adorner.SetCurrentValue(WatermarkAdorner.TextStyleProperty, textStyle);
                    }

                    AdornerService.Show(adorner);
                    adornedElement.SetCurrentValue(AdornerProperty, adorner);
                }
                else
                {
                    Debug.Assert(condition: false, message: "Already visible");
                }
            }
            else
            {
                var adorner = adornedElement.GetAdorner();
                if (adorner != null)
                {
                    AdornerService.Remove(adorner);
                    adornedElement.ClearValue(AdornerProperty);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Create a <see cref="ContentDragAdorner"/> that renders a <see cref="ContentPresenter"/> with Content, ContentTemplate and ContentTemplateSelector from <paramref name="adornedElement"/>.
        /// </summary>
        /// <param name="adornedElement">The drag source.</param>
        /// <returns>
        /// A <see cref="ContentDragAdorner"/> that should be disposed when the drag operation ends.
        /// Disposing it removes subscriptions and removes the adorner.
        /// </returns>
        public static ContentDragAdorner Create(ContentPresenter adornedElement)
        {
            var adorner = new ContentDragAdorner(adornedElement)
            {
                Content                 = adornedElement.Content,
                ContentTemplate         = adornedElement.ContentTemplate,
                ContentTemplateSelector = adornedElement.ContentTemplateSelector,
            };

            AdornerService.Show(adorner);
            return(adorner);
        }
예제 #7
0
 private static void OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (Equals(e.NewValue, true) &&
         d is UIElement element &&
         d.GetValue(TemplateProperty) is ControlTemplate template)
     {
         if (d.GetValue(AdornerProperty) is null)
         {
             var adorner = TemplatedAdorner.Create(element, template);
             d.SetCurrentValue(AdornerProperty, adorner);
             AdornerService.Show(adorner);
         }
         else
         {
             Debug.Assert(condition: false, message: $"Element {d} already has an info adorner.");
         }
     }
        /// <summary>
        /// Create a <see cref="ContentDragAdorner"/> that renders a <see cref="ContentPresenter"/> with Content, ContentTemplate and ContentTemplateSelector from <paramref name="adornedElement"/>.
        /// </summary>
        /// <param name="adornedElement">The drag source.</param>
        /// <returns>
        /// A <see cref="ContentDragAdorner"/> that should be disposed when the drag operation ends.
        /// Disposing it removes subscriptions and removes the adorner.
        /// </returns>
        public static ContentDragAdorner Create(ContentPresenter adornedElement)
        {
            if (adornedElement is null)
            {
                throw new ArgumentNullException(nameof(adornedElement));
            }

            var adorner = new ContentDragAdorner(adornedElement)
            {
                Content                 = adornedElement.Content,
                ContentTemplate         = adornedElement.ContentTemplate,
                ContentTemplateSelector = adornedElement.ContentTemplateSelector,
            };

            AdornerService.Show(adorner);
            return(adorner);
        }
예제 #9
0
        private static void OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Equals(e.NewValue, true))
            {
                if (d.GetValue(AdornerProperty) is null)
                {
                    var adorner = new ContentAdorner(AdornedElement())
                    {
                        Content                 = d.GetValue(ContentProperty),
                        ContentTemplate         = (DataTemplate)d.GetValue(ContentTemplateProperty),
                        ContentTemplateSelector = (DataTemplateSelector)d.GetValue(ContentTemplateSelectorProperty),
                        ContentPresenterStyle   = (Style)d.GetValue(ContentPresenterStyleProperty),
                    };
                    d.SetCurrentValue(AdornerProperty, adorner);
                    AdornerService.Show(adorner);
                }
                else
                {
                    Debug.Assert(condition: false, message: $"Element {d} already has an info adorner.");
                }
            }
            else if (d.GetValue(AdornerProperty) is ContentAdorner adorner)
            {
                AdornerService.Remove(adorner);
                d.ClearValue(AdornerProperty);
            }

            UIElement AdornedElement()
            {
                if (d is Window window &&
                    window.FirstRecursiveVisualChild <AdornerDecorator>() is { Child : { } adornerDecoratorChild })
                {
                    return(adornerDecoratorChild);
                }

                return((UIElement)d);
            }
예제 #10
0
        private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //Debug.Print($"Visible changed to: {e.NewValue}");
            var textBox = (TextBox)d;

            if (Equals(e.NewValue, true))
            {
                var adorner = textBox.GetAdorner();
                if (adorner == null)
                {
                    adorner = new WatermarkAdorner(textBox);
                    textBox.SetAdorner(adorner);
                    var textStyle = textBox.GetTextStyle();
                    if (textStyle != null)
                    {
                        adorner.SetCurrentValue(WatermarkAdorner.TextStyleProperty, textStyle);
                    }

                    AdornerService.Show(adorner);
                    textBox.SetValue(AdornerProperty, adorner);
                }
                else
                {
                    Debug.Assert(false, "Already visible");
                }
            }
            else
            {
                var adorner = textBox.GetAdorner();
                if (adorner != null)
                {
                    AdornerService.Remove(adorner);
                    textBox.ClearValue(AdornerProperty);
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Create a <see cref="ContentDragAdorner"/> that renders a <see cref="ContentPresenter"/>.
        /// The adorner is added to the adorner layer before it is returned.
        /// </summary>
        /// <param name="adornedElement">The drag source.</param>
        /// <param name="content">The content to drag.</param>
        /// <param name="contentTemplate">The template for the dragged content.</param>
        /// <param name="contentTemplateSelector">The template selector for the dragged content.</param>
        /// <returns>
        /// A <see cref="ContentDragAdorner"/> that should be disposed when the drag operation ends.
        /// Disposing it removes subscriptions and removes the adorner.
        /// </returns>
        public static ContentDragAdorner Create(
            UIElement adornedElement,
            object content,
            DataTemplate contentTemplate = null,
            DataTemplateSelector contentTemplateSelector = null)
        {
            var adorner = new ContentDragAdorner(adornedElement)
            {
                Content = content,
            };

            if (contentTemplate != null)
            {
                adorner.ContentTemplate = contentTemplate;
            }

            if (contentTemplateSelector != null)
            {
                adorner.ContentTemplateSelector = contentTemplateSelector;
            }

            AdornerService.Show(adorner);
            return(adorner);
        }