Esempio n. 1
0
        private static void ShowOverlayAdorner(DependencyObject targetElement, bool show, bool tryAgain)
        {
            var uiElement = targetElement as UIElement;

            if (uiElement == null)
            {
                return;
            }

            var adornerLayer = AdornerLayer.GetAdornerLayer(uiElement);

            if (adornerLayer == null)
            {
                if (tryAgain)
                {
                    // try again later, perhaps giving layout a chance to create the adorner layer
                    targetElement.Dispatcher.BeginInvoke(
                        DispatcherPriority.Loaded,
                        new DispatcherOperationCallback(ShowAdornerOperation),
                        new object[] { targetElement, show });
                }

                return;
            }

            var adorner = uiElement.ReadLocalValue(ToolTipAdornerProperty) as OverlayAdorner;

            if (show && adorner == null)
            {
                var overlayTemplate = GetOverlayTemplate(uiElement);
                var toolTip         = ToolTipService.GetToolTip(uiElement) as ToolTip;
                adorner = new OverlayAdorner(uiElement, toolTip, overlayTemplate);
                adornerLayer.Add(adorner);
                uiElement.SetCurrentValue(ToolTipAdornerProperty, adorner);
            }
            else if (!show && adorner != null)
            {
                adorner.ClearChild();
                adornerLayer.Remove(adorner);
                uiElement.ClearValue(ToolTipAdornerProperty);
            }
        }
        private static void ShowOverlayAdorner(DependencyObject targetElement, bool show, bool tryAgain)
        {
            var uiElement = targetElement as UIElement;
            if (uiElement == null)
            {
                return;
            }
            var adornerLayer = AdornerLayer.GetAdornerLayer(uiElement);

            if (adornerLayer == null)
            {
                if (tryAgain)
                {
                    // try again later, perhaps giving layout a chance to create the adorner layer
                    targetElement.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
                                new DispatcherOperationCallback(ShowAdornerOperation),
                                new object[] { targetElement, show });
                }
                return;
            }

            var adorner = uiElement.ReadLocalValue(ToolTipAdornerProperty) as OverlayAdorner;

            if (show && adorner == null)
            {
                var overlayTemplate = GetOverlayTemplate(uiElement);
                var toolTip = ToolTipService.GetToolTip(uiElement) as ToolTip;
                adorner = new OverlayAdorner(uiElement, toolTip, overlayTemplate);
                adornerLayer.Add(adorner);
                uiElement.SetValue(ToolTipAdornerProperty, adorner);
            }
            else if (!show && adorner != null)
            {
                adorner.ClearChild();
                adornerLayer.Remove(adorner);
                uiElement.ClearValue(ToolTipAdornerProperty);
            }
        }