Exemple #1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool handlesCommitKeys = ValueEditorUtils.GetHandlesCommitKeys(this);

            if (e.Key == Key.Return || e.Key == Key.Return)
            {
                StringEditor.LostFocusAction lostFocusAction = this.lostFocusAction;
                this.lostFocusAction = StringEditor.LostFocusAction.None;
                bool modifiers = (e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.None;
                if (lostFocusAction == StringEditor.LostFocusAction.Commit)
                {
                    if (!modifiers)
                    {
                        this.UpdateChange();
                    }
                    else
                    {
                        this.CommitChange();
                    }
                }
                if (modifiers)
                {
                    this.OnFinishEditing();
                }
                KeyEventArgs handled = e;
                handled.Handled = handled.Handled | handlesCommitKeys;
            }
            else if (e.Key == Key.Escape && this.IsEditing)
            {
                StringEditor.LostFocusAction lostFocusAction1 = this.lostFocusAction;
                this.lostFocusAction = StringEditor.LostFocusAction.None;
                if (lostFocusAction1 != StringEditor.LostFocusAction.None)
                {
                    this.CancelChange();
                }
                this.OnFinishEditing();
                KeyEventArgs keyEventArg = e;
                keyEventArg.Handled = keyEventArg.Handled | handlesCommitKeys;
            }
            base.OnKeyDown(e);
        }
Exemple #2
0
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            bool handlesCommitKeys = ValueEditorUtils.GetHandlesCommitKeys((DependencyObject)this);

            if (e.Key == Key.Return || e.Key == Key.Return)
            {
                KeyEventArgs keyEventArgs = e;
                int          num          = keyEventArgs.Handled | handlesCommitKeys ? 1 : 0;
                keyEventArgs.Handled = num != 0;
                ChoiceEditor.LostFocusAction lostFocusAction = this.lostFocusAction;
                this.lostFocusAction = ChoiceEditor.LostFocusAction.None;
                if (lostFocusAction == ChoiceEditor.LostFocusAction.Commit)
                {
                    this.CommitChange();
                }
                if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.None)
                {
                    this.OnFinishEditing();
                }
            }
            else if (e.Key == Key.Escape)
            {
                KeyEventArgs keyEventArgs = e;
                int          num          = keyEventArgs.Handled | handlesCommitKeys ? 1 : 0;
                keyEventArgs.Handled = num != 0;
                ChoiceEditor.LostFocusAction lostFocusAction = this.lostFocusAction;
                this.lostFocusAction = ChoiceEditor.LostFocusAction.None;
                if (lostFocusAction != ChoiceEditor.LostFocusAction.None)
                {
                    this.CancelChange();
                }
                this.OnFinishEditing();
            }
            if (this.InternalIsSelectingValue && this.collectionView != null && !this.collectionView.IsEmpty)
            {
                if (e.Key == Key.Up || !this.IsEditable && e.Key == Key.Left)
                {
                    this.SelectPreviousValue();
                    this.lostFocusAction = ChoiceEditor.LostFocusAction.Commit;
                    e.Handled            = true;
                }
                else if (e.Key == Key.Down || !this.IsEditable && e.Key == Key.Right)
                {
                    this.SelectNextValue();
                    this.lostFocusAction = ChoiceEditor.LostFocusAction.Commit;
                    e.Handled            = true;
                }
                else if (!this.IsEditable && e.Key == Key.Home)
                {
                    this.ValueIndex      = 0;
                    this.lostFocusAction = ChoiceEditor.LostFocusAction.Commit;
                    e.Handled            = true;
                }
                else if (!this.IsEditable && e.Key == Key.End)
                {
                    this.ValueIndex      = this.collectionView.Count - 1;
                    this.lostFocusAction = ChoiceEditor.LostFocusAction.Commit;
                    e.Handled            = true;
                }
            }
            base.OnPreviewKeyDown(e);
        }