Example #1
0
        // Token: 0x060053E1 RID: 21473 RVA: 0x00173EFC File Offset: 0x001720FC
        private void RaiseToolTipOpeningEvent(bool fromKeyboard = false)
        {
            this.ResetToolTipTimer();
            if (this._forceCloseTimer != null)
            {
                this.OnForceClose(null, EventArgs.Empty);
            }
            DependencyObject lastObjectWithToolTip = this.LastObjectWithToolTip;

            if (lastObjectWithToolTip != null)
            {
                bool          flag         = true;
                IInputElement inputElement = lastObjectWithToolTip as IInputElement;
                if (inputElement != null)
                {
                    ToolTipEventArgs toolTipEventArgs = new ToolTipEventArgs(true);
                    inputElement.RaiseEvent(toolTipEventArgs);
                    flag = !toolTipEventArgs.Handled;
                }
                if (flag)
                {
                    object  toolTip  = ToolTipService.GetToolTip(lastObjectWithToolTip);
                    ToolTip toolTip2 = toolTip as ToolTip;
                    if (toolTip2 != null)
                    {
                        this._currentToolTip = toolTip2;
                        this._ownToolTip     = false;
                    }
                    else if (this._currentToolTip == null || !this._ownToolTip)
                    {
                        this._currentToolTip = new ToolTip();
                        this._ownToolTip     = true;
                        this._currentToolTip.SetValue(PopupControlService.ServiceOwnedProperty, BooleanBoxes.TrueBox);
                        Binding binding = new Binding();
                        binding.Path   = new PropertyPath(ToolTipService.ToolTipProperty);
                        binding.Mode   = BindingMode.OneWay;
                        binding.Source = lastObjectWithToolTip;
                        this._currentToolTip.SetBinding(ContentControl.ContentProperty, binding);
                    }
                    if (!this._currentToolTip.StaysOpen)
                    {
                        throw new NotSupportedException(SR.Get("ToolTipStaysOpenFalseNotAllowed"));
                    }
                    this._currentToolTip.SetValue(PopupControlService.OwnerProperty, lastObjectWithToolTip);
                    this._currentToolTip.Opened      += new RoutedEventHandler(this.OnToolTipOpened);
                    this._currentToolTip.Closed      += new RoutedEventHandler(this.OnToolTipClosed);
                    this._currentToolTip.FromKeyboard = fromKeyboard;
                    this._currentToolTip.IsOpen       = true;
                    this.ToolTipTimer          = new DispatcherTimer(DispatcherPriority.Normal);
                    this.ToolTipTimer.Interval = TimeSpan.FromMilliseconds((double)ToolTipService.GetShowDuration(lastObjectWithToolTip));
                    this.ToolTipTimer.Tick    += this.OnRaiseToolTipClosingEvent;
                    this.ToolTipTimer.Start();
                }
            }
        }
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();
                }
            }
        }