Exemplo n.º 1
0
        private static void UpdateAdroner(UIElement adorned, bool isVisible, ControlTemplate controlTemplate)
        {
            var layer = AdornerLayer.GetAdornerLayer(adorned);

            if (layer == null)
            {
                // if we don't have an adorner layer it's probably
                // because it's too early in the window's construction
                // Let's re-run at a slightly later time
                Dispatcher.CurrentDispatcher.BeginInvoke(
                    DispatcherPriority.Background,
                    new Action <UIElement>(o =>
                {
                    if (AdornerLayer.GetAdornerLayer(o) == null)
                    {
                        System.Diagnostics.Debug.WriteLine("AdornerLib.Adorrners: Error - no adorner layer");
                        return;
                    }
                    UpdateAdroner(o);
                }), adorned);
                return;
            }

            var existingAdorner = GetInteranlAdorner(adorned);

            if (existingAdorner == null)
            {
                if (controlTemplate != null && isVisible)
                {
                    // show
                    var newAdorner = new ControlAdorner(adorned);
                    newAdorner.Child = new Control()
                    {
                        Template = controlTemplate, Focusable = false,
                    };
                    layer.Add(newAdorner);
                    SetInternalAdorner(adorned, newAdorner);
                }
            }
            else
            {
                if (controlTemplate != null && isVisible)
                {
                    // switch template
                    Control ctrl = existingAdorner.Child;
                    ctrl.Template = controlTemplate;
                }
                else
                {
                    // hide
                    existingAdorner.Child = null;
                    layer.Remove(existingAdorner);
                    SetInternalAdorner(adorned, null);
                }
            }
        }
Exemplo n.º 2
0
        private static void UpdateAdroner(UIElement adorned, bool isVisible, ControlTemplate controlTemplate)
        {
            var layer = AdornerLayer.GetAdornerLayer(adorned);

            if (layer == null)
            {
                // if we don't have an adorner layer it's probably
                // because it's too early in the window's construction
                // Let's re-run at a slightly later time
                Dispatcher.CurrentDispatcher.BeginInvoke(
                    DispatcherPriority.Background,
                    new Action<UIElement>(o =>
                    {
                        if(AdornerLayer.GetAdornerLayer(o) == null)
                        {
                            System.Diagnostics.Debug.WriteLine("AdornerLib.Adorrners: Error - no adorner layer");
                            return;
                        }
                        UpdateAdroner(o);
                    }), adorned);
                return;
            }

            var existingAdorner = GetInteranlAdorner(adorned);

            if (existingAdorner == null)
            {
                if (controlTemplate != null && isVisible)
                {
                    // show
                    var newAdorner = new ControlAdorner(adorned);
                    newAdorner.Child = new Control() { Template = controlTemplate, Focusable = false, };
                    layer.Add(newAdorner);
                    SetInternalAdorner(adorned, newAdorner);
                }
            }
            else
            {
                if (controlTemplate != null && isVisible)
                {
                    // switch template
                    Control ctrl = existingAdorner.Child;
                    ctrl.Template = controlTemplate;
                }
                else
                {
                    // hide
                    existingAdorner.Child = null;
                    layer.Remove(existingAdorner);
                    SetInternalAdorner(adorned, null);
                }
            }
        }
Exemplo n.º 3
0
 public static void SetInternalAdorner(DependencyObject target, ControlAdorner value)
 {
     target.SetValue(InternalAdornerProperty, value);
 }
Exemplo n.º 4
0
 public static void SetInternalAdorner(DependencyObject target, ControlAdorner value)
 {
     target.SetValue(InternalAdornerProperty, value);
 }