コード例 #1
0
        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.UserControlSelf = (Gallery)target;
                break;

            case 7:
                this.CategoryListBox = (SelectingListBox)target;
                break;

            default:
                this._contentLoaded = true;
                break;
            }
        }
コード例 #2
0
        private void CategoryListBox_KeyDown(object sender, KeyEventArgs e)
        {
            SelectingListBox selectingListBox = sender as SelectingListBox;

            if (e.Handled || selectingListBox == null || !selectingListBox.IsKeyboardFocusWithin)
            {
                return;
            }
            FocusNavigationDirection focusNavigationDirection;

            switch (e.Key)
            {
            case Key.Left:
                focusNavigationDirection = FocusNavigationDirection.Left;
                break;

            case Key.Up:
                focusNavigationDirection = FocusNavigationDirection.Up;
                break;

            case Key.Right:
                focusNavigationDirection = FocusNavigationDirection.Right;
                break;

            case Key.Down:
                focusNavigationDirection = FocusNavigationDirection.Down;
                break;

            default:
                return;
            }
            TraversalRequest request = new TraversalRequest(focusNavigationDirection);

            if (Keyboard.FocusedElement is SelectingListBoxItem)
            {
                SelectingListBoxItem selectingListBoxItem = Keyboard.FocusedElement as SelectingListBoxItem;
                KeyEventArgs         keyEventArgs         = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key);
                keyEventArgs.RoutedEvent = Gallery.SelectedItemKeyDownEvent;
                keyEventArgs.Source      = (object)selectingListBoxItem;
                this.RaiseEvent((RoutedEventArgs)keyEventArgs);
                if (!keyEventArgs.Handled)
                {
                    selectingListBoxItem.MoveFocus(request);
                }
                e.Handled = true;
            }
            else
            {
                Expander parentExpander = this.FindParentExpander(Keyboard.FocusedElement as DependencyObject);
                if (parentExpander == null || !parentExpander.IsKeyboardFocusWithin)
                {
                    return;
                }
                switch (focusNavigationDirection)
                {
                case FocusNavigationDirection.Left:
                    if (parentExpander.IsExpanded)
                    {
                        parentExpander.IsExpanded = false;
                        break;
                    }
                    break;

                case FocusNavigationDirection.Right:
                    if (!parentExpander.IsExpanded)
                    {
                        parentExpander.IsExpanded = true;
                        break;
                    }
                    break;

                default:
                    UIElement uiElement = Keyboard.FocusedElement as UIElement;
                    if (uiElement != null)
                    {
                        uiElement.MoveFocus(request);
                        break;
                    }
                    break;
                }
                e.Handled = true;
            }
        }