Example #1
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);
            }
        }
Example #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 = 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);
            }
        }
Example #3
0
        private static void SetIfNotNull(
            DependencyObject source,
            DependencyProperty sourceProperty,
            ContentAdorner adorner,
            DependencyProperty adornerProperty)
        {
            var value = source.GetValue(sourceProperty);

            if (value != null)
            {
                adorner.SetValue(adornerProperty, value);
            }
        }
Example #4
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);
            }
Example #5
0
 private static void SetAdorner(this DependencyObject element, ContentAdorner value)
 {
     element.SetValue(AdornerProperty, value);
 }