Example #1
0
        /// <summary>
        /// The register tooltip.
        /// </summary>
        /// <param name="owner">
        /// The owner.
        /// </param>
        /// <param name="p">
        /// The p.
        /// </param>
        private static void RegisterTooltip(UIElement owner, object p)
        {
            if (owner == null)
            {
                return;
            }

            lock (Locker)
            {
                if (ElementsAndToolTips.ContainsKey(owner))
                {
                    return;
                }
            }

            var             element = owner as FrameworkElement;
            PinnableTooltip toolTip = null;

            if (p != null)
            {
                toolTip = p as PinnableTooltip ?? ConvertToTooltip(p);
                toolTip.SetOwner(owner);
            }

            if (element != null)
            {
                element.Unloaded += FrameworkElementUnloaded;
                if (toolTip != null)
                {
                    toolTip.DataContext = element.DataContext;
                }
            }

            owner.MouseEnter += OnElementMouseEnter;
            owner.MouseLeave += OnElementMouseLeave;

            var control = owner as Control;

            if (control != null)
            {
                control.IsEnabledChanged += OnControlEnabledChanged;
            }

            lock (Locker)
            {
                ElementsAndToolTips[owner] = toolTip;
            }
        }
Example #2
0
        /// <summary>
        /// The unregister tooltip.
        /// </summary>
        /// <param name="owner">
        /// The owner.
        /// </param>
        private static void UnregisterTooltip(UIElement owner)
        {
            try
            {
                if (owner == null)
                {
                    return;
                }

                lock (Locker)
                {
                    PinnableTooltip toolTip = null;
                    if (ElementsAndToolTips.ContainsKey(owner))
                    {
                        toolTip = ElementsAndToolTips[owner];
                    }
                    else
                    {
                        return;
                    }

                    var element = owner as FrameworkElement;
                    if (element != null)
                    {
                        element.Unloaded   -= FrameworkElementUnloaded;
                        toolTip.DataContext = null;
                    }

                    owner.MouseEnter -= OnElementMouseEnter;
                    owner.MouseLeave -= OnElementMouseLeave;

                    var control = owner as Control;
                    if (control != null)
                    {
                        control.IsEnabledChanged -= OnControlEnabledChanged;
                    }

                    toolTip.IsOpen = false;
                    toolTip.SetOwner(null);
                    ElementsAndToolTips.Remove(owner);
                }
            }
            catch (Exception)
            {
            }
        }