示例#1
0
        private void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                if (KeyboardHelper.AreKeyboardModifiersPressed(ModifierKeys.Control))
                {
                    UpdateSuggestionBox(true);
                    e.Handled = true;
                }
            }

            if (e.Key == Key.Down)
            {
                if (_suggestionListBox.SelectedIndex < _suggestionListBox.Items.Count)
                {
                    _suggestionListBox.SelectedIndex = _suggestionListBox.SelectedIndex + 1;
                }
            }

            if (e.Key == Key.Up)
            {
                if (_suggestionListBox.SelectedIndex > -1)
                {
                    _suggestionListBox.SelectedIndex = _suggestionListBox.SelectedIndex - 1;
                }
            }

            if (e.Key == Key.Enter || e.Key == Key.Tab)
            {
                // Commit the selection
                UpdateSuggestionBox(false);
                e.Handled = (e.Key == Key.Enter);

                var binding = AssociatedObject.GetBindingExpression(TextBox.TextProperty);
                if (binding != null)
                {
                    binding.UpdateSource();
                }
            }

            if (e.Key == Key.Escape)
            {
                if (_popup.IsOpen)
                {
                    // Cancel the selection
                    UpdateSuggestionBox(false);

                    _isUpdatingAssociatedObject = true;

                    AssociatedObject.Text = _valueAtSuggestionBoxOpen;
                    e.Handled             = true;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Invokes the command with the overriden parameter.
        /// <para />
        /// If the <see cref="CommandParameter"/> should be used, use the <see cref="ExecuteCommand()"/> instead.
        /// </summary>
        /// <param name="parameter">The parameter that will override the <see cref="CommandParameter"/>.</param>
        protected virtual void ExecuteCommand(object parameter)
        {
            // CTL-638
            if (Modifiers != ModifierKeys.None)
            {
                if (!KeyboardHelper.AreKeyboardModifiersPressed(Modifiers))
                {
                    return;
                }
            }

            if (CanExecuteCommand(parameter))
            {
                _command.Execute(parameter);
            }
        }
示例#3
0
        private static bool IsDigit(Key key)
        {
            bool isDigit;

            var isShiftKey = KeyboardHelper.AreKeyboardModifiersPressed(ModifierKeys.Shift);

            if (key >= Key.D0 && key <= Key.D9 && !isShiftKey)
            {
                isDigit = true;
            }
            else
            {
                isDigit = key >= Key.NumPad0 && key <= Key.NumPad9;
            }

            return(isDigit);
        }
示例#4
0
        protected override void Initialize()
        {
            base.Initialize();

            var adornerLayer = AdornerLayer.GetAdornerLayer(Adorner ?? AssociatedObject);

            if (adornerLayer == null)
            {
                Log.Error("Cannot find AdornerLayer. Use the Adorner property to specify a specific instance to use when searching for an adorner layer");
                return;
            }

            if (KeyboardHelper.AreKeyboardModifiersPressed(System.Windows.Input.ModifierKeys.Alt))
            {
                var adorneredTooltipsManager = _adorneredTooltipsManagerFactory.Create(adornerLayer);
                adorneredTooltipsManager.Enable();
            }
        }
示例#5
0
        /// <summary>
        /// Determines whether the command can be invoked. It does this by checking both the <see cref="Modifiers"/> and
        /// the command itself.
        /// <para />
        /// If the <see cref="CommandParameter"/> should be used, use the <see cref="CanExecuteCommand()"/> instead.
        /// </summary>
        /// <returns><c>true</c> if the command can be invoked; otherwise, <c>false</c>.</returns>
        protected virtual bool CanExecuteCommand(object parameter)
        {
            var command = _command;

            if (command == null)
            {
                return(false);
            }

            if (Modifiers != ModifierKeys.None)
            {
                if (!KeyboardHelper.AreKeyboardModifiersPressed(Modifiers))
                {
                    return(false);
                }
            }

            return(command.CanExecute(parameter));
        }
示例#6
0
        /// <summary>
        /// Called when the specified key is pressed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The key event args instance containing the event data.</param>
        private void OnKeyDown(object sender, KeyDownEventArgs e)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (e.Handled)
            {
                return;
            }

            if (KeyboardHelper.AreKeyboardModifiersPressed(Modifiers))
            {
                if (e.Key == Key)
                {
                    StartFocus();

                    e.Handled = true;
                }
            }
        }