Пример #1
0
        /// <summary>
        /// The on element mouse leave.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private static void OnElementMouseLeave(object sender, MouseEventArgs e)
        {
            PinnableToolTip toolTip = null;

            lock (Locker)
            {
                var currentElement = (UIElement)sender;
                if (ElementsAndToolTips.ContainsKey(currentElement))
                {
                    toolTip = ElementsAndToolTips[currentElement];
                }
                else
                {
                    return;
                }
            }

            if (toolTip == null)
            {
                return;
            }

            if (!toolTip.IsOpen)
            {
                toolTip.StopTimer();
            }
        }
Пример #2
0
        /// <summary>
        /// The on element mouse enter.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private static void OnElementMouseEnter(object sender, MouseEventArgs e)
        {
            UIElement       currentElement;
            PinnableToolTip toolTip = null;

            lock (Locker)
            {
                currentElement = sender as UIElement;
                if (currentElement != null)
                {
                    if (ElementsAndToolTips.ContainsKey(currentElement))
                    {
                        toolTip = ElementsAndToolTips[currentElement];
                    }
                    else
                    {
                        return;
                    }
                }

                MousePosition = e.GetPosition(null);
                SetRootVisual();
            }

            if (toolTip == null || (toolTip.Content == null && toolTip.ContentTemplate == null) || toolTip.IsTimerEnabled || toolTip.IsOpen)
            {
                return;
            }

            var initialShowDelay = GetInitialShowDelay(currentElement);
            var showDuration     = GetShowDuration(currentElement);

            toolTip.SetupTimer(initialShowDelay, showDuration);
            toolTip.StartTimer();
        }
Пример #3
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;
                        if (toolTip != null)
                        {
                            toolTip.SetValue(FrameworkElement.DataContextProperty, null);
                        }
                    }

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

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

                    if (toolTip != null)
                    {
                        toolTip.Hide();
                        toolTip.Owner = null;
                    }

                    ElementsAndToolTips.Remove(owner);
                }
            }
            catch (Exception)
            {
                // Ignore
            }
        }
Пример #4
0
        /// <summary>
        /// The framework element unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private static void FrameworkElementUnloaded(object sender, RoutedEventArgs e)
        {
            var             element = (UIElement)sender;
            PinnableToolTip toolTip = null;

            lock (Locker)
            {
                if (ElementsAndToolTips.ContainsKey(element))
                {
                    toolTip = ElementsAndToolTips[element];
                }
            }

            toolTip?.Hide();
        }
Пример #5
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.Owner = owner;
            }

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

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

            var control = owner as Control;

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

            lock (Locker)
            {
                ElementsAndToolTips[owner] = toolTip;
            }
        }
Пример #6
0
        /// <summary>
        /// The on placement target property changed.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <param name="e">The e.</param>
        private static void OnPlacementTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = (UIElement)d;

            PinnableToolTip toolTip = null;

            lock (Locker)
            {
                if (ElementsAndToolTips.ContainsKey(element))
                {
                    toolTip = ElementsAndToolTips[element];
                }
            }

            if (toolTip != null && toolTip.IsOpen)
            {
                toolTip.PerformPlacement();
            }
        }
Пример #7
0
        /// <summary>
        /// The on control enabled changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private static void OnControlEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                return;
            }

            var             element = (UIElement)sender;
            PinnableToolTip toolTip = null;

            lock (Locker)
            {
                if (ElementsAndToolTips.ContainsKey(element))
                {
                    toolTip = ElementsAndToolTips[element];
                }
            }

            toolTip?.StopTimer();
        }