public LiveToolTipAdorner(UIElement adornedElement, LiveToolTip tooltip)
            : base(adornedElement)
        {
            visualChildren    = new VisualCollection(this);
            FollowMouseCursor = LiveToolTipService.GetFollowMouseCursor(adornedElement);
            ToolTipOffset     = new Point(LiveToolTipService.GetToolTipOffsetX(adornedElement), LiveToolTipService.GetToolTipOffsetY(adornedElement));

            adornedElement.MouseLeave += adornedElement_MouseLeave;
            adornedElement.MouseEnter += adornedElement_MouseEnter;
            if (FollowMouseCursor)
            {
                adornedElement.PreviewMouseMove += adornedElement_MouseMove;
            }
            //FrameworkElement frAdornedElement = (FrameworkElement)adornedElement;
            //frAdornedElement.SizeChanged += frAdornedElement_SizeChanged;

            this.liveTooltip = tooltip;

            tooltip.Visibility = Visibility.Hidden;

            var parentCanvas = liveTooltip.Parent as Canvas;

            if (parentCanvas != null)
            {
                parentCanvas.Children.Remove(liveTooltip);
            }

            canvas.Children.Add(liveTooltip);
            AddLogicalChild(canvas);
            visualChildren.Add(canvas);

            Unloaded += LiveTooltipAdorner_Unloaded;
        }
        private static void AddTooltip(FrameworkElement source)
        {
            if (DesignerProperties.GetIsInDesignMode(source))
            {
                return;
            }

            LiveToolTip tooltip = GetLiveToolTip(source);

            Window           window = Window.GetWindow(source);
            FrameworkElement child  = source;
            FrameworkElement parent = null;

            if (window != null)
            {
                while (parent != window)
                {
                    parent = (FrameworkElement)VisualTreeHelper.GetParent(child);
                    child  = parent;
                    var nameScope = NameScope.GetNameScope(parent);
                    if (nameScope != null)
                    {
                        string nameScopeName = nameScope.ToString();
                        if (nameScopeName != "System.Windows.TemplateNameScope")
                        {
                            NameScope.SetNameScope(tooltip, nameScope);
                            break;
                        }
                    }
                }
            }

            var binding = BindingOperations.GetBinding(tooltip, LiveToolTip.ContentProperty);

            if (binding != null)
            {
                BindingOperations.ClearBinding(tooltip, LiveToolTip.ContentProperty);
                BindingOperations.SetBinding(tooltip, LiveToolTip.ContentProperty, binding);
            }

            Binding dataContextBinding = new Binding {
                Path = new PropertyPath("DataContext"), Source = source
            };

            tooltip.SetBinding(LiveToolTip.DataContextProperty, dataContextBinding);

            tooltip.Owner = source;
            if (GetTooltipOpacity(source) != (double)LiveToolTipService.TooltipOpacityProperty.DefaultMetadata.DefaultValue)
            {
                tooltip.Opacity = LiveToolTipService.GetTooltipOpacity(source);
            }

            AddTooltipForElement(source, tooltip);
        }