예제 #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 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;
            }
        }
예제 #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;
                        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)
            {
            }
        }
예제 #4
0
        /// <summary>
        /// The on placement target property changed.
        /// </summary>
        /// <param name="d">
        /// The d.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private static void OnPlacementTargetPropertyChanged(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();
            }
        }
예제 #5
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)
        {
#if (SILVERLIGHT)
            UnregisterTooltip(sender as UIElement);
#else
            var             element = (UIElement)sender;
            PinnableTooltip tooltip = null;
            lock (Locker)
            {
                if (ElementsAndToolTips.ContainsKey(element))
                {
                    tooltip = ElementsAndToolTips[element];
                }
            }

            if (tooltip != null)
            {
                tooltip.IsOpen = false;
            }
#endif
        }
예제 #6
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];
                }
            }

            if (tooltip != null)
            {
                tooltip.StopTimer();
            }
        }
예제 #7
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 (ElementsAndToolTips.ContainsKey(currentElement))
                {
                    toolTip = ElementsAndToolTips[currentElement];
                }
                else
                {
                    return;
                }

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

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

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

            if (initialShowDelay == 0)
            {
                toolTip.IsOpen = true;
            }

            toolTip.SetupTimer(initialShowDelay, showDuration);
            toolTip.StartTimer();
        }