Microsoft.Windows.Controls.Ribbon.RibbonComboBox.OnKeyDown C# (CSharp) Method

OnKeyDown() protected method

protected OnKeyDown ( System.Windows.Input.KeyEventArgs e ) : void
e System.Windows.Input.KeyEventArgs
return void
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            bool handled = false;
            if ((e.Key == Key.Escape) &&
                IsSelectedItemCached &&
                (IsDropDownOpen || IsEditable))
            {
                // Cancel changes of escape
                if (IsEditable && !IsDropDownOpen)
                {
                    handled = true;
                }
                CommitOrCancelChanges(false /* cancelChanges */);
            }

            if ((e.Key == Key.F4) &&
                IsSelectedItemCached &&
                IsDropDownOpen)
            {
                // Cancel changes on F4
                CommitOrCancelChanges(false /* cancelChanges */);
            }

            UIElement targetFocusOnFalse = null;
            if (IsEditable)
            {
                targetFocusOnFalse = EditableTextBoxSite;
            }
            else if (RetainFocusOnEscape)
            {
                targetFocusOnFalse = PartToggleButton;
            }
            RibbonHelper.HandleDropDownKeyDown(this,
                e,
                delegate() { return IsDropDownOpen; },
                delegate(bool value) { IsDropDownOpen = value; },
                targetFocusOnFalse,
                Popup.TryGetChild());

            if (e.Handled)
            {
                return;
            }

            Key key = e.Key;
            if (key == Key.System)
            {
                key = e.SystemKey;
            }

            switch (key)
            {
                case Key.Enter:
                case Key.F10:
                    if (IsEditable || IsDropDownOpen)
                    {
                        // Commit changes on Enter or F10.
                        CommitOrCancelChanges(true /* commitChanges */);

                        // Dismiss parent Popups
                        RaiseEvent(new RibbonDismissPopupEventArgs());

                        handled = true;
                    }
                    break;
            }

            if (handled)
            {
                e.Handled = true;
            }

            base.OnKeyDown(e);
        }