コード例 #1
0
        private void ChangeFocus(UIElement focus, DateTime timestamp)
        {
            if (focus != this._focus)
            {
                // Update the critical pieces of data.
                var oldFocus = this._focus;
                this._focus = focus;
                this._focusRootUIElement = focus?.RootUIElement;

                // Adjust the handlers we use to track everything.
                if (oldFocus != null)
                {
                    oldFocus.IsEnabledChanged -= this._isEnabledOrVisibleChangedEventHandler;
                    oldFocus.IsVisibleChanged -= this._isEnabledOrVisibleChangedEventHandler;
                }

                if (focus != null)
                {
                    focus.IsEnabledChanged += this._isEnabledOrVisibleChangedEventHandler;
                    focus.IsVisibleChanged += this._isEnabledOrVisibleChangedEventHandler;
                }

                // Send the LostFocus and GotFocus events.
                if (oldFocus != null)
                {
                    var lostFocus = new FocusChangedEventArgs(this, timestamp, oldFocus, focus)
                    {
                        RoutedEvent = Buttons.LostFocusEvent,
                        Source      = oldFocus
                    };

                    this._inputManager.ProcessInput(lostFocus);
                }

                if (focus != null)
                {
                    var gotFocus = new FocusChangedEventArgs(this, timestamp, oldFocus, focus)
                    {
                        RoutedEvent = Buttons.GotFocusEvent,
                        Source      = focus
                    };

                    this._inputManager.ProcessInput(gotFocus);
                }
            }
        }
コード例 #2
0
        private void ChangeFocus(UIElement focus, DateTime timestamp)
        {
            if (focus == this._focus)
            {
                return;
            }
            UIElement focus1 = this._focus;

            this._focus = focus;
            this._focusRootUIElement = focus?.RootUIElement;
            if (focus1 != null)
            {
                focus1.IsEnabledChanged -= this._isEnabledOrVisibleChangedEventHandler;
                focus1.IsVisibleChanged -= this._isEnabledOrVisibleChangedEventHandler;
            }
            if (focus != null)
            {
                focus.IsEnabledChanged += this._isEnabledOrVisibleChangedEventHandler;
                focus.IsVisibleChanged += this._isEnabledOrVisibleChangedEventHandler;
            }
            if (focus1 != null)
            {
                FocusChangedEventArgs changedEventArgs = new FocusChangedEventArgs(this, timestamp, focus1, focus);
                changedEventArgs.RoutedEvent = Buttons.LostFocusEvent;
                changedEventArgs.Source      = (object)focus1;
                this._inputManager.ProcessInput((InputEventArgs)changedEventArgs);
            }
            if (focus == null)
            {
                return;
            }
            FocusChangedEventArgs changedEventArgs1 = new FocusChangedEventArgs(this, timestamp, focus1, focus);

            changedEventArgs1.RoutedEvent = Buttons.GotFocusEvent;
            changedEventArgs1.Source      = (object)focus;
            this._inputManager.ProcessInput((InputEventArgs)changedEventArgs1);
        }