Пример #1
0
        internal override bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
        {
            bool returnValue = base.FocusItem(info, itemNavigateArgs);

            // Trying to navigate from the current menuitem (this) to an adjacent menuitem.

            if (itemNavigateArgs.DeviceUsed is KeyboardDevice)
            {
                // If the item is a TopLevelHeader then when you navigate onto it, the submenu will open
                // and we should select the first item in the submenu.  The parent MenuItem will take care
                // of opening the submenu but doesn't know whether focus changed because of a mouse action
                // or a keyboard action.  Help out by focusing the first thing in the new submenu.

                // Assume that KeyboardNavigation.Current.Navigate moved focus onto the element onto which
                // it navigated.
                MenuItem newSelection = info.Container as MenuItem;
                if (newSelection != null &&
                    newSelection.Role == MenuItemRole.TopLevelHeader &&
                    newSelection.IsSubmenuOpen)
                {
                    newSelection.NavigateToStart(itemNavigateArgs);
                }
            }
            return(returnValue);
        }
Пример #2
0
        /// <summary>
        ///     Called when an item is being focused
        /// </summary>
        internal override bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
        {
            // Base will actually focus the item
            bool returnValue = base.FocusItem(info, itemNavigateArgs);

            ListBoxItem listItem = info.Container as ListBoxItem;

            if (listItem != null)
            {
                LastActionItem = listItem;

                // pass in the modifier keys!!  Use items instead as well.
                MakeKeyboardSelection(listItem);
            }
            return(returnValue);
        }
Пример #3
0
 /// <summary>
 ///     Called when an item is being focused
 /// </summary>
 internal override bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
 {
     object item = info.Item;
     bool returnValue = false;
     if (item != null)
     {
         DataGridColumn column = CurrentColumn;
         if (column == null)
         {
             SetCurrentItem(item);
         }
         else
         {
             DataGridCell cell = TryFindCell(info, column);
             if (cell != null)
             {
                 cell.Focus();
                 if (ShouldSelectRowHeader)
                 {
                     HandleSelectionForRowHeaderAndDetailsInput(cell.RowOwner, /* startDragging = */ false);
                 }
                 else
                 {
                     HandleSelectionForCellInput(cell, /* startDragging = */ false, /* allowsExtendSelect = */ false, /* allowsMinimalSelect = */ false);
                 }
             }
         }
     }
     if (itemNavigateArgs.DeviceUsed is KeyboardDevice)
     {
         KeyboardNavigation.ShowFocusVisual();
     }
     return returnValue;
 }
Пример #4
0
        internal override bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
        {
            bool returnValue = base.FocusItem(info, itemNavigateArgs);
            // Trying to navigate from the current menuitem (this) to an adjacent menuitem.

            if (itemNavigateArgs.DeviceUsed is KeyboardDevice)
            {
                // If the item is a TopLevelHeader then when you navigate onto it, the submenu will open
                // and we should select the first item in the submenu.  The parent MenuItem will take care
                // of opening the submenu but doesn't know whether focus changed because of a mouse action
                // or a keyboard action.  Help out by focusing the first thing in the new submenu.

                // Assume that KeyboardNavigation.Current.Navigate moved focus onto the element onto which
                // it navigated.
                MenuItem newSelection = info.Container as MenuItem;
                if (newSelection != null
                    && newSelection.Role == MenuItemRole.TopLevelHeader
                    && newSelection.IsSubmenuOpen)
                {
                    newSelection.NavigateToStart(itemNavigateArgs);
                }
            }
            return returnValue;
        }
Пример #5
0
        /// <summary>
        ///     Called when an item is being focused
        /// </summary> 
        internal override void FocusItem(object item, ItemNavigateArgs itemNavigateArgs)
        { 
            // Base will actually focus the item 
            base.FocusItem(item, itemNavigateArgs);
 
            ListBoxItem listItem = ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;

            if (listItem != null)
            { 
                LastActionItem = listItem;
 
                // 
                MakeKeyboardSelection(listItem);
            } 
        }
Пример #6
0
        private bool NavigateToFirstItemOnCurrentPage(object startingItem, FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs, bool shouldFocus, out FrameworkElement container)
        {
            object firstItem = GetFirstItemOnCurrentPage(ItemContainerGenerator.ContainerFromItem(startingItem) as FrameworkElement,
                direction,
                out container);

            if (firstItem != DependencyProperty.UnsetValue)
            {
                if (shouldFocus)
                {
                    return FocusItem(NewItemInfo(firstItem, container), itemNavigateArgs);
                }
            }
            return false;
        }
Пример #7
0
 internal void NavigateToItem(object item, ItemNavigateArgs itemNavigateArgs, bool alwaysAtTopOfViewport)
 {
     NavigateToItem(item, -1, itemNavigateArgs, alwaysAtTopOfViewport);
 }
Пример #8
0
 internal void NavigateToItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs, bool alwaysAtTopOfViewport=false)
 {
     if (info != null)
     {
         NavigateToItem(info.Item, info.Index, itemNavigateArgs, alwaysAtTopOfViewport);
     }
 }
Пример #9
0
        private void NavigateToFirstItemOnCurrentPage(object startingItem, FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs)
        {
            int foundIndex; 
            object firstItem = GetFirstItemOnCurrentPage(startingItem, direction, out foundIndex);
 
            if (firstItem != DependencyProperty.UnsetValue) 
            {
                FocusItem(firstItem, itemNavigateArgs); 
            }
        }
Пример #10
0
        private void NavigateToItem(object item, int elementIndex, ItemNavigateArgs itemNavigateArgs, bool alwaysAtTopOfViewport)
        { 
            //
 
            // Perhaps the container isn't generated yet.  In this case we try to shift the view, 
            // wait for measure, and then call it again.
            if (item == DependencyProperty.UnsetValue) 
            {
                return;
            }
 
            if (elementIndex == -1)
            { 
                elementIndex = Items.IndexOf(item); 
                if (elementIndex == -1)
                    return; 
            }

            while (MakeVisible(elementIndex, alwaysAtTopOfViewport, false /* alignMinorAxisToo */))
            { 
                // The above operations to change VerticalOffset might have invalidated measure.
                // Try again after measure. 
                Debug.Assert(ItemsHost != null); 

 
                double oldHorizontalOffset = ScrollHost.HorizontalOffset;
                double oldVerticalOffset = ScrollHost.VerticalOffset;

                ItemsHost.UpdateLayout(); 

                // If offset does not change - exit the loop 
                if (DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) && 
                    DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset))
                    break; 
            }

            FocusItem(item, itemNavigateArgs);
        } 
Пример #11
0
 internal void NavigateToEnd(ItemNavigateArgs itemNavigateArgs)
 { 
     if (HasItems) 
     {
         int foundIndex; 
         object item = FindFocusable(Items.Count - 1, -1, out foundIndex);
         NavigateToItem(item, foundIndex, itemNavigateArgs);
     }
 } 
Пример #12
0
 internal void NavigateToStart(ItemNavigateArgs itemNavigateArgs) 
 {
     if (HasItems) 
     { 
         int foundIndex;
         object item = FindFocusable(0, 1, out foundIndex); 
         NavigateToItem(item, foundIndex, itemNavigateArgs);
     }
 }
Пример #13
0
        private void NavigateByPageInternal(object startingItem, FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs)
        { 
            // Move to the last guy on the page if we're not already there. 
            if (startingItem == null)
            { 
                NavigateToFirstItemOnCurrentPage(startingItem, direction, itemNavigateArgs);
            }
            else
            { 
                // See if the currently focused guy is the first or last one one the page
                int firstIndex; 
                object first = GetFirstItemOnCurrentPage(startingItem, direction, out firstIndex); 

                if (startingItem.Equals(first)) 
                {
                    // Page in that direction
                    bool navigateAfterMeasure = false;
 
                    if (ScrollHost != null)
                    { 
                        switch (direction) 
                        {
                            case FocusNavigationDirection.Up: 
                                if (IsLogicalHorizontal)
                                {
                                    ScrollHost.PageLeft();
                                } 
                                else
                                { 
                                    ScrollHost.PageUp(); 
                                }
 
                                navigateAfterMeasure = true;
                                break;

                            case FocusNavigationDirection.Down: 
                                if (IsLogicalHorizontal)
                                { 
                                    ScrollHost.PageRight(); 
                                }
                                else 
                                {
                                    ScrollHost.PageDown();
                                }
 
                                navigateAfterMeasure = true;
                                break; 
                        } 
                    }
 
                    // After measure we should focus the first guy on the page
                    if (navigateAfterMeasure)
                    {
                        if (ItemsHost != null) 
                        {
                            ItemsHost.UpdateLayout(); 
                            NavigateToFirstItemOnCurrentPage(startingItem, direction, itemNavigateArgs); 
                        }
                    } 
                }
                else
                {
                    // The currently focused guy is not the first on the page, so move there 
                    if (first != DependencyProperty.UnsetValue)
                    { 
                        NavigateToItem(first, firstIndex, itemNavigateArgs); 
                    }
                } 
            }
        }
Пример #14
0
        internal void NavigateByPage(object startingItem, FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs) 
        {
            if (ItemsHost == null) 
            { 
                return;
            } 

            // If the focused item has been scrolled out of view and they want to
            // start navigating again, scroll it back into view.
            if (startingItem != null && !IsOnCurrentPage(startingItem, direction)) 
            {
                while (MakeVisible(Items.IndexOf(startingItem))) 
                { 
                    double oldHorizontalOffset = ScrollHost.HorizontalOffset;
                    double oldVerticalOffset = ScrollHost.VerticalOffset; 

                    ItemsHost.UpdateLayout();

                    // If offset does not change - exit the loop 
                    if (DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) &&
                        DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset)) 
                        break; 
                }
            } 

            NavigateByPageInternal(startingItem, direction, itemNavigateArgs);
        }
Пример #15
0
 internal void NavigateByPage(FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs)
 { 
     NavigateByPage(FocusedItem, direction, itemNavigateArgs);
 }
Пример #16
0
        private void NavigateByLineInternal(object startingItem, FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs)
        {
            // If there is no starting item, just navigate to the first item. 
            if (startingItem == null)
            { 
                NavigateToStart(itemNavigateArgs); 
            }
            else 
            {
                FrameworkElement startingElement = null;
                FrameworkElement nextElement = null;
 
                startingElement = ItemContainerGenerator.ContainerFromItem(startingItem) as FrameworkElement;
                // If the container isn't there, it might have been degenerated or 
                // it might have been scrolled out of view.  Either way, we 
                // should start navigation from the ItemsHost b/c we know it
                // is visible. 
                // The generator could have given us an element which isn't
                // actually visually connected.  In this case we should use
                // the ItemsHost as well.
                if (startingElement == null || !ItemsHost.IsAncestorOf(startingElement)) 
                {
                    // Bug 991220 makes it so that we have to start from the ScrollHost. 
                    // If we try to start from the ItemsHost it will always skip the first item. 
                    startingElement = ScrollHost;
                } 

                nextElement = KeyboardNavigation.Current.PredictFocusedElement(startingElement, direction) as FrameworkElement;

                // We can only navigate there if the target element is in the items host. 
                if ((nextElement != null) && (ItemsHost.IsAncestorOf(nextElement)))
                { 
                    object nextItem = GetEncapsulatingItem(nextElement); 

                    if (nextItem != DependencyProperty.UnsetValue) 
                    {
                        NavigateToItem(nextItem, itemNavigateArgs);
                    }
                } 
            }
        } 
Пример #17
0
        internal bool NavigateToEndInternal(ItemNavigateArgs itemNavigateArgs, bool shouldFocus, out FrameworkElement container)
        {
            container = null;

            if (ItemsHost != null)
            {
                if (ScrollHost != null)
                {
                    double oldHorizontalOffset = 0.0;
                    double oldVerticalOffset = 0.0;
                    bool isHorizontal = (ItemsHost.HasLogicalOrientation && ItemsHost.LogicalOrientation == Orientation.Horizontal);

                    do
                    {
                        oldHorizontalOffset = ScrollHost.HorizontalOffset;
                        oldVerticalOffset = ScrollHost.VerticalOffset;

                        if (isHorizontal)
                        {
                            ScrollHost.ScrollToRightEnd();
                        }
                        else
                        {
                            ScrollHost.ScrollToBottom();
                        }

                        // Wait for layout
                        ItemsHost.UpdateLayout();
                    }
                    // If offset does not change - exit the loop
                    while (!DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) ||
                           !DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset));
                }

                FrameworkElement lastElement;
                FrameworkElement hopefulLastElement = FindEndFocusableLeafContainer(ItemsHost, true /*last*/);
                object lastItem = GetFirstItemOnCurrentPage(hopefulLastElement,
                    FocusNavigationDirection.Down,
                    out lastElement);
                container = lastElement;
                if (shouldFocus)
                {
                    if (lastElement != null &&
                        (lastItem == DependencyProperty.UnsetValue || lastItem is CollectionViewGroupInternal))
                    {
                        return lastElement.Focus();
                    }
                    else
                    {
                        ItemsControl itemsControl = GetEncapsulatingItemsControl(lastElement);
                        if (itemsControl != null)
                        {
                            return itemsControl.FocusItem(NewItemInfo(lastItem, lastElement), itemNavigateArgs);
                        }
                    }
                }
            }
            return false;
        }
Пример #18
0
 //
 internal virtual void FocusItem(object item, ItemNavigateArgs itemNavigateArgs)
 { 
     if (item != null)
     { 
         UIElement container = ItemContainerGenerator.ContainerFromItem(item) as UIElement; 
         if (container != null)
         { 
             Keyboard.Focus(container);
         }
     }
     if (itemNavigateArgs.DeviceUsed is KeyboardDevice) 
     {
         KeyboardNavigation.ShowFocusVisual(); 
     } 
 }
Пример #19
0
 internal void NavigateToItem(object item, int itemIndex, ItemNavigateArgs itemNavigateArgs)
 {
     NavigateToItem(item, itemIndex, itemNavigateArgs, false /* alwaysAtTopOfViewport */);
 }
Пример #20
0
        internal void PrepareNavigateByLine(ItemInfo startingInfo,
            FrameworkElement startingElement,
            FocusNavigationDirection direction,
            ItemNavigateArgs itemNavigateArgs,
            out FrameworkElement container)
        {
            container = null;
            if (ItemsHost == null)
            {
                return;
            }

            // If the focused container/item has been scrolled out of view and they want to
            // start navigating again, scroll it back into view.
            if (startingElement != null)
            {
                MakeVisible(startingElement, direction, false);
            }
            else
            {
                MakeVisible(startingInfo, direction, out startingElement);
            }

            object startingItem = (startingInfo != null) ? startingInfo.Item : null;

            // When we get here if startingItem is non-null, it must be on the visible page.
            NavigateByLineInternal(startingItem,
                direction,
                startingElement,
                itemNavigateArgs,
                false /*shouldFocus*/,
                out container);
        }
Пример #21
0
        private void NavigateToItem(object item, int elementIndex, ItemNavigateArgs itemNavigateArgs, bool alwaysAtTopOfViewport)
        {
            // 

            // Perhaps the container isn't generated yet.  In this case we try to shift the view,
            // wait for measure, and then call it again.
            if (item == DependencyProperty.UnsetValue)
            {
                return;
            }

            if (elementIndex == -1)
            {
                elementIndex = Items.IndexOf(item);
                if (elementIndex == -1)
                    return;
            }

            bool isHorizontal = false;
            if (ItemsHost != null)
            {
                isHorizontal = (ItemsHost.HasLogicalOrientation && ItemsHost.LogicalOrientation == Orientation.Horizontal);
            }

            FrameworkElement container;
            FocusNavigationDirection direction = isHorizontal ? FocusNavigationDirection.Right : FocusNavigationDirection.Down;
            MakeVisible(elementIndex, direction, alwaysAtTopOfViewport, out container);

            FocusItem(NewItemInfo(item, container), itemNavigateArgs);
        }
Пример #22
0
        private bool NavigateByLineInternal(object startingItem,
            FocusNavigationDirection direction,
            FrameworkElement startingElement,
            ItemNavigateArgs itemNavigateArgs,
            bool shouldFocus,
            out FrameworkElement container)
        {
            container = null;

            //
            // If there is no starting item, just navigate to the first item.
            //
            if (startingItem == null &&
                (startingElement == null || startingElement == this))
            {
                return NavigateToStartInternal(itemNavigateArgs, shouldFocus, out container);
            }
            else
            {
                FrameworkElement nextElement = null;

                //
                // If the container isn't there, it might have been degenerated or
                // it might have been scrolled out of view.  Either way, we
                // should start navigation from the ItemsHost b/c we know it
                // is visible.
                // The generator could have given us an element which isn't
                // actually visually connected.  In this case we should use
                // the ItemsHost as well.
                //
                if (startingElement == null || !ItemsHost.IsAncestorOf(startingElement))
                {
                    //
                    // Bug 991220 makes it so that we have to start from the ScrollHost.
                    // If we try to start from the ItemsHost it will always skip the first item.
                    //
                    startingElement = ScrollHost;
                }
                else
                {
                    // if the starting element is with in an element with contained or cycle scope
                    // then let the default keyboard navigation logic kick in.
                    DependencyObject startingParent = VisualTreeHelper.GetParent(startingElement);
                    while (startingParent != null &&
                        startingParent != ItemsHost)
                    {
                        KeyboardNavigationMode mode = KeyboardNavigation.GetDirectionalNavigation(startingParent);
                        if (mode == KeyboardNavigationMode.Contained ||
                            mode == KeyboardNavigationMode.Cycle)
                        {
                            return false;
                        }
                        startingParent = VisualTreeHelper.GetParent(startingParent);
                    }
                }

                bool isHorizontal = (ItemsHost != null && ItemsHost.HasLogicalOrientation && ItemsHost.LogicalOrientation == Orientation.Horizontal);
                bool treeViewNavigation = (this is TreeView);
                nextElement = KeyboardNavigation.Current.PredictFocusedElement(startingElement,
                    direction,
                    treeViewNavigation) as FrameworkElement;

                if (ScrollHost != null)
                {
                    bool didScroll = false;
                    FrameworkElement viewport = GetViewportElement();
                    VirtualizingPanel virtualizingPanel = ItemsHost as VirtualizingPanel;
                    bool isCycle = KeyboardNavigation.GetDirectionalNavigation(this) == KeyboardNavigationMode.Cycle;

                    while (true)
                    {
                        if (nextElement != null)
                        {
                            if (virtualizingPanel != null &&
                                ScrollHost.CanContentScroll &&
                                VirtualizingPanel.GetIsVirtualizing(this))
                            {
                                Rect currentRect;
                                ElementViewportPosition elementPosition = GetElementViewportPosition(viewport,
                                    TryGetTreeViewItemHeader(nextElement) as FrameworkElement,
                                    direction,
                                    false /*fullyVisible*/,
                                    out currentRect);
                                if (elementPosition == ElementViewportPosition.CompletelyInViewport ||
                                    elementPosition == ElementViewportPosition.PartiallyInViewport)
                                {
                                    if (!isCycle)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        Rect startingRect;
                                        GetElementViewportPosition(viewport,
                                            startingElement,
                                            direction,
                                            false /*fullyVisible*/,
                                            out startingRect);
                                        bool isInDirection = IsInDirectionForLineNavigation(startingRect, currentRect, direction, isHorizontal);
                                        if (isInDirection)
                                        {
                                            // If the next element in cycle mode is in direction
                                            // then this is a valid candidate, If not then try
                                            // scrolling.
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }

                            //
                            // We are disregarding the previously predicted element because
                            // it is outside the viewport extents of a VirtualizingPanel
                            //
                            nextElement = null;
                        }

                        double oldHorizontalOffset = ScrollHost.HorizontalOffset;
                        double oldVerticalOffset = ScrollHost.VerticalOffset;

                        switch (direction)
                        {
                            case FocusNavigationDirection.Down:
                                {
                                    didScroll = true;
                                    if (isHorizontal)
                                    {
                                        ScrollHost.LineRight();
                                    }
                                    else
                                    {
                                        ScrollHost.LineDown();
                                    }
                                }
                                break;
                            case FocusNavigationDirection.Up:
                                {
                                    didScroll = true;
                                    if (isHorizontal)
                                    {
                                        ScrollHost.LineLeft();
                                    }
                                    else
                                    {
                                        ScrollHost.LineUp();
                                    }
                                }
                                break;
                        }

                        ScrollHost.UpdateLayout();

                        // If offset does not change, or if offset goes out of range - exit the loop.
                        // The out-of-range check is to defend against buggy implementations of
                        // IScrollInfo (as in Dev11 476647);  WPF's implementations always leave the
                        // offset within range.
                        if ((DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) &&
                            DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset))
                            || (direction == FocusNavigationDirection.Down &&
                                    (ScrollHost.VerticalOffset > ScrollHost.ExtentHeight ||
                                     ScrollHost.HorizontalOffset > ScrollHost.ExtentWidth))
                            || (direction == FocusNavigationDirection.Up &&
                                    (ScrollHost.VerticalOffset < 0.0 ||
                                     ScrollHost.HorizontalOffset < 0.0)))
                        {
                            if (isCycle)
                            {
                                if (direction == FocusNavigationDirection.Up)
                                {
                                    // If scrollviewer cannot be scrolled any further,
                                    // then cycle and navigate to end.
                                    return NavigateToEndInternal(itemNavigateArgs, true, out container);
                                }
                                else if (direction == FocusNavigationDirection.Down)
                                {
                                    // If scrollviewer cannot be scrolled any further,
                                    // then cycle and navigate to start.
                                    return NavigateToStartInternal(itemNavigateArgs, true, out container);
                                }
                            }
                            break;
                        }

                        nextElement = KeyboardNavigation.Current.PredictFocusedElement(startingElement,
                            direction,
                            treeViewNavigation) as FrameworkElement;
                    }

                    if (didScroll && nextElement != null && ItemsHost.IsAncestorOf(nextElement))
                    {
                        // Adjust offset so that the nextElement is aligned to the edge
                        AdjustOffsetToAlignWithEdge(nextElement, direction);
                    }
                }

                // We can only navigate there if the target element is in the items host.
                if ((nextElement != null) && (ItemsHost.IsAncestorOf(nextElement)))
                {
                    ItemsControl itemsControl = null;
                    object nextItem = GetEncapsulatingItem(nextElement, out container, out itemsControl);
                    container = nextElement;

                    if (shouldFocus)
                    {
                        if (nextItem == DependencyProperty.UnsetValue || nextItem is CollectionViewGroupInternal)
                        {
                            return nextElement.Focus();
                        }
                        else if (itemsControl != null)
                        {
                            return itemsControl.FocusItem(NewItemInfo(nextItem, container), itemNavigateArgs);
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return false;
        }
Пример #23
0
        // 
        internal virtual bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
        {
            object item = info.Item;
            bool returnValue = false;

            if (item != null)
            {
                UIElement container =  info.Container as UIElement;
                if (container != null)
                {
                    returnValue = container.Focus();
                }
            }
            if (itemNavigateArgs.DeviceUsed is KeyboardDevice)
            {
                KeyboardNavigation.ShowFocusVisual();
            }
            return returnValue;
        }
Пример #24
0
 internal bool NavigateByPage(FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs)
 {
     return NavigateByPage(FocusedInfo, Keyboard.FocusedElement as FrameworkElement, direction, itemNavigateArgs);
 }
Пример #25
0
        /// <summary>
        ///     Called when an item is being focused
        /// </summary>
        internal override bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
        {
            bool returnValue = false;
            // The base implementation sets focus, and we don't want to do that
            // if we're editable.
            if (!IsEditable)
            {
                returnValue = base.FocusItem(info, itemNavigateArgs);
            }

            ComboBoxItem cbi = info.Container as ComboBoxItem;
            HighlightedInfo = (cbi != null) ? info : null;

            // When IsEditable is 'true', we'll always want to commit the selection. e.g. when user press KeyUp/Down.
            // However, when IsEditable is 'false' and Dropdown is open, we could get here when user navigate to
            // the item using ITS. In this case, we don't want to commit the selection.
            if ((IsEditable || (!IsDropDownOpen)) && itemNavigateArgs.DeviceUsed is KeyboardDevice)
            {
                int index = info.Index;

                if (index < 0)
                {
                    index = Items.IndexOf(info.Item);
                }

                SetCurrentValueInternal(SelectedIndexProperty, index);

                returnValue = true;
            }
            return returnValue;
        }
Пример #26
0
 internal bool NavigateByPage(
     ItemInfo startingInfo,
     FocusNavigationDirection direction,
     ItemNavigateArgs itemNavigateArgs)
 {
     return NavigateByPage(startingInfo, null, direction, itemNavigateArgs);
 }
Пример #27
0
        /// <summary>
        ///     Called when an item is being focused
        /// </summary>
        internal override bool FocusItem(ItemInfo info, ItemNavigateArgs itemNavigateArgs)
        {
            // Base will actually focus the item
            bool returnValue = base.FocusItem(info, itemNavigateArgs);

            ListBoxItem listItem = info.Container as ListBoxItem;

            if (listItem != null)
            {
                LastActionItem = listItem;

                // 
                MakeKeyboardSelection(listItem);
            }
            return returnValue;
        }
Пример #28
0
        internal bool NavigateByPage(
            ItemInfo startingInfo,
            FrameworkElement startingElement,
            FocusNavigationDirection direction,
            ItemNavigateArgs itemNavigateArgs)
        {
            if (ItemsHost == null)
            {
                return false;
            }

            // If the focused container/item has been scrolled out of view and they want to
            // start navigating again, scroll it back into view.
            if (startingElement != null)
            {
                MakeVisible(startingElement, direction, /*alwaysAtTopOfViewport*/ false);
            }
            else
            {
                MakeVisible(startingInfo, direction, out startingElement);
            }

            object startingItem = (startingInfo != null) ? startingInfo.Item : null;

            // When we get here if startingItem is non-null, it must be on the visible page.
            FrameworkElement container;
            return NavigateByPageInternal(startingItem,
                direction,
                startingElement,
                itemNavigateArgs,
                true /*shouldFocus*/,
                out container);
        }
Пример #29
0
        private bool NavigateByPageInternal(object startingItem,
            FocusNavigationDirection direction,
            FrameworkElement startingElement,
            ItemNavigateArgs itemNavigateArgs,
            bool shouldFocus,
            out FrameworkElement container)
        {
            container = null;

            //
            // Move to the last guy on the page if we're not already there.
            //
            if (startingItem == null &&
                (startingElement == null || startingElement == this))
            {
                return NavigateToFirstItemOnCurrentPage(startingItem, direction, itemNavigateArgs, shouldFocus, out container);
            }
            else
            {
                //
                // See if the currently focused guy is the first or last one one the page
                //
                FrameworkElement firstElement;
                object firstItem = GetFirstItemOnCurrentPage(startingElement, direction, out firstElement);

                if ((object.Equals(startingItem, firstItem) ||
                    object.Equals(startingElement, firstElement)) &&
                    ScrollHost != null)
                {
                    bool isHorizontal = (ItemsHost.HasLogicalOrientation && ItemsHost.LogicalOrientation == Orientation.Horizontal);

                    do
                    {
                        double oldHorizontalOffset = ScrollHost.HorizontalOffset;
                        double oldVerticalOffset = ScrollHost.VerticalOffset;

                        switch (direction)
                        {
                            case FocusNavigationDirection.Up:
                                {
                                    if (isHorizontal)
                                    {
                                        ScrollHost.PageLeft();
                                    }
                                    else
                                    {
                                        ScrollHost.PageUp();
                                    }
                                }
                                break;

                            case FocusNavigationDirection.Down:
                                {
                                    if (isHorizontal)
                                    {
                                        ScrollHost.PageRight();
                                    }
                                    else
                                    {
                                        ScrollHost.PageDown();
                                    }
                                }
                                break;
                        }

                        ScrollHost.UpdateLayout();

                        // If offset does not change - exit the loop
                        if (DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) &&
                            DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset))
                            break;

                        firstItem = GetFirstItemOnCurrentPage(startingElement, direction, out firstElement);
                    }
                    while (firstItem == DependencyProperty.UnsetValue);
                }

                container = firstElement;
                if (shouldFocus)
                {
                    if (firstElement != null &&
                        (firstItem == DependencyProperty.UnsetValue || firstItem is CollectionViewGroupInternal))
                    {
                        return firstElement.Focus();
                    }
                    else
                    {
                        ItemsControl itemsControl = GetEncapsulatingItemsControl(firstElement);
                        if (itemsControl != null)
                        {
                            return itemsControl.FocusItem(NewItemInfo(firstItem, firstElement), itemNavigateArgs);
                        }
                    }
                }
            }
            return false;
        }
Пример #30
0
 internal void NavigateToEnd(ItemNavigateArgs itemNavigateArgs)
 {
     FrameworkElement container;
     NavigateToEndInternal(itemNavigateArgs, true /*shouldFocus*/, out container);
 }
Пример #31
0
        /// <summary>
        ///     Called when an item is being focused 
        /// </summary>
        internal override void FocusItem(object item, ItemNavigateArgs itemNavigateArgs)
        {
            // The base implementation sets focus, and we don't want to do that 
            // if we're editable.
            if (!IsEditable) 
            { 
                base.FocusItem(item, itemNavigateArgs);
            } 

            ComboBoxItem highlightedElement = ItemContainerGenerator.ContainerFromItem(item) as ComboBoxItem;
            HighlightedElement = highlightedElement;
 
            // When IsEditable is 'true', we'll always want to commit the selection. e.g. when user press KeyUp/Down.
            // However, when IsEditable is 'false' and Dropdown is open, we could get here when user navigate to 
            // the item using ITS. In this case, we don't want to commit the selection. 
            if ((IsEditable || (!IsDropDownOpen)) && itemNavigateArgs.DeviceUsed is KeyboardDevice)
            { 
                if (highlightedElement != null)
                {
                    SetCurrentValueInternal(SelectedIndexProperty, ItemContainerGenerator.IndexFromContainer(highlightedElement));
                } 
                else
                { 
                    SetCurrentValueInternal(SelectedIndexProperty, Items.IndexOf(item)); 
                }
            } 
        }
Пример #32
0
        internal void NavigateByLine(object startingItem, FocusNavigationDirection direction, ItemNavigateArgs itemNavigateArgs) 
        {
            if (ItemsHost == null)
            {
                return; 
            }
 
            // If the focused item has been scrolled out of view and they want to 
            // start navigating again, scroll it back into view.
            if (startingItem != null && !IsOnCurrentPage(startingItem, direction)) 
            {
                MakeVisible(Items.IndexOf(startingItem));
                // Wait for layout
                ItemsHost.UpdateLayout(); 
            }
 
            // When we get here if startingItem is non-null, it must be on the visible page. 
            NavigateByLineInternal(startingItem, direction, itemNavigateArgs);
        }