Example #1
0
        private void RaiseToolTipClosingEvent(bool reset)
        {
            this.ResetToolTipTimer();
            if (reset)
            {
                this.LastChecked = null;
            }
            DependencyObject lastMouseOverWithToolTip = this.LastMouseOverWithToolTip;

            if (lastMouseOverWithToolTip != null && this._currentToolTip != null)
            {
                bool isOpen = this._currentToolTip.IsOpen;
                try
                {
                    if (isOpen)
                    {
                        IInputElement inputElement = lastMouseOverWithToolTip as IInputElement;
                        if (inputElement != null)
                        {
                            inputElement.RaiseEvent(new ToolTipEventArgs(false));
                        }
                    }
                }
                finally
                {
                    if (isOpen)
                    {
                        this._currentToolTip.IsOpen = false;
                        if (this._currentToolTip != null)
                        {
                            this._forceCloseTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                            this._forceCloseTimer.Interval = Popup.AnimationDelayTime;
                            this._forceCloseTimer.Tick    += new EventHandler(this.OnForceClose);
                            this._forceCloseTimer.Tag      = this._currentToolTip;
                            this._forceCloseTimer.Start();
                        }
                        this._quickShow            = true;
                        this.ToolTipTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                        this.ToolTipTimer.Interval = TimeSpan.FromMilliseconds((double)ToolTipService.GetBetweenShowDelay(lastMouseOverWithToolTip));
                        this.ToolTipTimer.Tick    += new EventHandler(this.OnBetweenShowDelay);
                        this.ToolTipTimer.Start();
                    }
                    else
                    {
                        this._currentToolTip.ClearValue(PopupControlService.OwnerProperty);
                        if (this._ownToolTip)
                        {
                            BindingOperations.ClearBinding(this._currentToolTip, ContentControl.ContentProperty);
                        }
                    }
                    this._currentToolTip = null;
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Closes the current tooltip, firing a Closing event if necessary.
        /// </summary>
        /// <param name="reset">
        ///     When false, will continue to treat input as if the tooltip were open so that
        ///     the tooltip of the current element won't re-open. Example: Clicking on a button
        ///     will hide the tooltip, but when the mouse is released, the tooltip should not
        ///     appear unless the mouse is moved off and then back on the button.
        /// </param>
        private void RaiseToolTipClosingEvent(bool reset)
        {
            ResetToolTipTimer();

            if (reset)
            {
                LastChecked = null;
            }

            DependencyObject o = LastObjectWithToolTip;

            if (o != null)
            {
                if (_currentToolTip != null)
                {
                    bool isOpen = _currentToolTip.IsOpen;

                    try
                    {
                        if (isOpen)
                        {
                            IInputElement element = o as IInputElement;
                            if (element != null)
                            {
                                element.RaiseEvent(new ToolTipEventArgs(false));
                            }
                        }
                    }
                    finally
                    {
                        // Raising an event calls out to app code, which
                        // could cause a re-entrant call to this method that
                        // sets _currentToopTip to null.  If that happens,
                        // there's no need to do the work again.
                        if (_currentToolTip != null)
                        {
                            if (isOpen)
                            {
                                _currentToolTip.IsOpen = false;

                                // Setting IsOpen makes call outs to app code. So it is possible that
                                // the _currentToolTip is destroyed as a result of an action there. If that
                                // were the case we do not need to set off the timer to close the tooltip.
                                if (_currentToolTip != null)
                                {
                                    // Keep references and owner set for the fade out or slide animation
                                    // Owner is released when animation completes
                                    _forceCloseTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                                    _forceCloseTimer.Interval = Popup.AnimationDelayTime;
                                    _forceCloseTimer.Tick    += new EventHandler(OnForceClose);
                                    _forceCloseTimer.Tag      = _currentToolTip;
                                    _forceCloseTimer.Start();
                                }

                                _quickShow            = true;
                                ToolTipTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                                ToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetBetweenShowDelay(o));
                                ToolTipTimer.Tick    += new EventHandler(OnBetweenShowDelay);
                                ToolTipTimer.Start();
                            }
                            else
                            {
                                // Release owner now
                                _currentToolTip.ClearValue(OwnerProperty);

                                if (_ownToolTip)
                                {
                                    BindingOperations.ClearBinding(_currentToolTip, ToolTip.ContentProperty);
                                }
                            }

                            if (_currentToolTip != null)
                            {
                                _currentToolTip.FromKeyboard = false;
                                _currentToolTip = null;
                            }
                        }
                    }
                }
            }
        }