Example #1
0
        /// <summary>
        ///     This is the method that responds to the KeyDown event.
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.Handled)
            {
                return;
            }

            Key key = e.Key;

            switch (key)
            {
            case Key.Down:
            case Key.Up:
                if (CurrentSelection != null)
                {
                    // Only for non vertical layout Up/Down open the submenu
                    Panel itemsHost  = ItemsHost;
                    bool  isVertical = itemsHost != null && itemsHost.HasLogicalOrientation && itemsHost.LogicalOrientation == Orientation.Vertical;
                    if (!isVertical)
                    {
                        CurrentSelection.OpenSubmenuWithKeyboard();
                        e.Handled = true;
                    }
                }
                break;

            case Key.Left:
            case Key.Right:
                if (CurrentSelection != null)
                {
                    // Only for vertical layout Left/Right open the submenu
                    Panel itemsHost  = ItemsHost;
                    bool  isVertical = itemsHost != null && itemsHost.HasLogicalOrientation && itemsHost.LogicalOrientation == Orientation.Vertical;
                    if (isVertical)
                    {
                        CurrentSelection.OpenSubmenuWithKeyboard();
                        e.Handled = true;
                    }
                }
                break;
            }
        }