System.Windows.Controls.AutoCompleteBox.OnKeyDown C# (CSharp) Méthode

OnKeyDown() protected méthode

Provides handling for the E:System.Windows.UIElement.KeyDown event.
protected OnKeyDown ( System.Windows.Input.KeyEventArgs e ) : void
e System.Windows.Input.KeyEventArgs A /// that contains the event data.
Résultat void
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if(e == null)
            {
                throw new ArgumentNullException("e");
            }

            base.OnKeyDown(e);

            if(e.Handled || !IsEnabled)
            {
                return;
            }

            // The drop down is open, pass along the key event arguments to the
            // selection adapter. If it isn't handled by the adapter's logic,
            // then we handle some simple navigation scenarios for controlling
            // the drop down.
            if(IsDropDownOpen)
            {
                if(SelectionAdapter != null)
                {
                    SelectionAdapter.HandleKeyDown(e);
                    if(e.Handled)
                    {
                        return;
                    }
                }

                if(e.Key == Key.Escape)
                {
                    OnAdapterSelectionCanceled(this, new RoutedEventArgs());
                    e.Handled = true;
                }
            }
            else
            {
                // The drop down is not open, the Down key will toggle it open.
                if(e.Key == Key.Down)
                {
                    IsDropDownOpen = true;
                    e.Handled = true;
                }
            }

            // Standard drop down navigation
            switch(e.Key)
            {
                case Key.F4:
                    IsDropDownOpen = !IsDropDownOpen;
                    e.Handled = true;
                    break;

                case Key.Enter:
                    OnAdapterSelectionComplete(this, new RoutedEventArgs());
                    e.Handled = true;
                    break;
            }
        }