public static void SetAutoMoveVerticalOffset(ToolTip element, double value)
 {
     element.SetValue(AutoMoveVerticalOffsetProperty, value);
 }
Example #2
0
        /// <summary>
        ///     Initiates the process of opening the tooltip popup.
        /// </summary>
        /// <param name="fromKeyboard">
        ///     Whether this particular event is caused by keyboard focus.
        ///     This is passed down to the tooltip and the popup to determine its placement.
        /// </param>
        private void RaiseToolTipOpeningEvent(bool fromKeyboard = false)
        {
            ResetToolTipTimer();

            if (_forceCloseTimer != null)
            {
                OnForceClose(null, EventArgs.Empty);
            }

            DependencyObject o = LastObjectWithToolTip;

            if (o != null)
            {
                bool show = true;

                IInputElement element = o as IInputElement;
                if (element != null)
                {
                    ToolTipEventArgs args = new ToolTipEventArgs(true);
                    element.RaiseEvent(args);

                    show = !args.Handled;
                }

                if (show)
                {
                    object  tooltip = ToolTipService.GetToolTip(o);
                    ToolTip tip     = tooltip as ToolTip;
                    if (tip != null)
                    {
                        _currentToolTip = tip;
                        _ownToolTip     = false;
                    }
                    else if ((_currentToolTip == null) || !_ownToolTip)
                    {
                        _currentToolTip = new ToolTip();
                        _ownToolTip     = true;
                        _currentToolTip.SetValue(ServiceOwnedProperty, BooleanBoxes.TrueBox);

                        // Bind the content of the tooltip to the ToolTip attached property
                        Binding binding = new Binding();
                        binding.Path   = new PropertyPath(ToolTipService.ToolTipProperty);
                        binding.Mode   = BindingMode.OneWay;
                        binding.Source = o;
                        _currentToolTip.SetBinding(ToolTip.ContentProperty, binding);
                    }

                    if (!_currentToolTip.StaysOpen)
                    {
                        // The popup takes capture in this case, which causes us to hit test to the wrong window.
                        // We do not support this scenario. Cleanup and then throw and exception.
                        throw new NotSupportedException(SR.Get(SRID.ToolTipStaysOpenFalseNotAllowed));
                    }

                    _currentToolTip.SetValue(OwnerProperty, o);
                    _currentToolTip.Opened      += OnToolTipOpened;
                    _currentToolTip.Closed      += OnToolTipClosed;
                    _currentToolTip.FromKeyboard = fromKeyboard;
                    _currentToolTip.IsOpen       = true;

                    ToolTipTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                    ToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetShowDuration(o));
                    ToolTipTimer.Tick    += new EventHandler(OnRaiseToolTipClosingEvent);
                    ToolTipTimer.Start();
                }
            }
        }
 public static void SetAutoMove(ToolTip element, bool value)
 {
     element.SetValue(AutoMoveProperty, value);
 }
Example #4
0
        private void RaiseToolTipOpeningEvent()
        {
            ResetToolTipTimer();

            if (_forceCloseTimer != null)
            {
                OnForceClose(null, EventArgs.Empty);
            }

            DependencyObject o = LastMouseOverWithToolTip;
            if (o != null)
            {
                bool show = true;

                IInputElement element = o as IInputElement;
                if (element != null)
                {
                    ToolTipEventArgs args = new ToolTipEventArgs(true);
                    element.RaiseEvent(args);

                    show = !args.Handled;
                }

                if (show)
                {
                    object tooltip = ToolTipService.GetToolTip(o);
                    ToolTip tip = tooltip as ToolTip;
                    if (tip != null)
                    {
                        _currentToolTip = tip;
                        _ownToolTip = false;
                    }
                    else if ((_currentToolTip == null) || !_ownToolTip)
                    {
                        _currentToolTip = new ToolTip();
                        _ownToolTip = true;
                        _currentToolTip.SetValue(ServiceOwnedProperty, BooleanBoxes.TrueBox);

                        // Bind the content of the tooltip to the ToolTip attached property
                        Binding binding = new Binding();
                        binding.Path = new PropertyPath(ToolTipService.ToolTipProperty);
                        binding.Mode = BindingMode.OneWay;
                        binding.Source = o;
                        _currentToolTip.SetBinding(ToolTip.ContentProperty, binding);
                    }

                    if (!_currentToolTip.StaysOpen)
                    {
                        // The popup takes capture in this case, which causes us to hit test to the wrong window.
                        // We do not support this scenario. Cleanup and then throw and exception.
                        throw new NotSupportedException(SR.Get(SRID.ToolTipStaysOpenFalseNotAllowed));
                    }

                    _currentToolTip.SetValue(OwnerProperty, o);
                    _currentToolTip.Closed += OnToolTipClosed;
                    _currentToolTip.IsOpen = true;

                    ToolTipTimer = new DispatcherTimer(DispatcherPriority.Normal);
                    ToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetShowDuration(o));
                    ToolTipTimer.Tick += new EventHandler(OnRaiseToolTipClosingEvent);
                    ToolTipTimer.Start();
                }
            }
        }