Exemplo n.º 1
0
        private static void UpdateAdornerLayer(FrameworkElement element, bool elevate, bool loaded = false)
        {
            var adornerLayer = AdornerLayer.GetAdornerLayer(element);

            if (adornerLayer == null)
            {
                if (!loaded)
                {
                    element.Dispatcher.InvokeAsync(() => UpdateAdornerLayer(element, elevate, true), DispatcherPriority.Loaded);
                }

                return;
            }

            var info = GetFrameworkElementAdornerInfo(element);

            if (elevate)
            {
                if (info == null)
                {
                    var parent = VisualTreeHelper.GetParent(element) as Panel;
                    if (parent == null)
                    {
                        return;
                    }
                    var index = parent.Children.IndexOf(element);
                    parent.Children.RemoveAt(index);
                    parent.Children.Insert(index, new Control());
                    var frameworkElementAdorner = new FrameworkElementAdorner(element);
                    frameworkElementAdorner.Child = element;

                    info = new FrameworkElementAdornerInfo
                    {
                        Parent  = parent,
                        Index   = index,
                        Adorner = frameworkElementAdorner
                    };

                    adornerLayer.Add(frameworkElementAdorner);
                    SetFrameworkElementAdornerInfo(element, info);
                }
            }
            else
            {
                if (info != null)
                {
                    info.Adorner.Child = null;
                    SetFrameworkElementAdornerInfo(element, null);
                    adornerLayer.Remove(info.Adorner);
                    info.Parent.Children.RemoveAt(info.Index);
                    info.Parent.Children.Insert(info.Index, element);
                }
            }
        }
Exemplo n.º 2
0
 public static void SetFrameworkElementAdornerInfo(DependencyObject obj, FrameworkElementAdornerInfo value)
 {
     obj.SetValue(FrameworkElementAdornerInfoProperty, value);
 }