コード例 #1
0
        /// <summary>
        /// Moves keyboard focus the specified number of steps away from the currently focused item.
        /// </summary>
        /// <param name="step">The number of steps by which to move focus.</param>
        private void MoveItemFocus(Int32 step)
        {
            var selectedContainer = ItemsControlUtil.FindFocusedContainer <ComboBoxItem>(this);
            var selectedIndex     = (selectedContainer == null) ? -1 : ItemContainers.IndexOf(selectedContainer);

            var targetIndex = selectedIndex + step;

            if (targetIndex < 0 || targetIndex >= Items.Count)
            {
                return;
            }

            var targetContainer = ItemContainers[targetIndex] as UIElement;

            if (targetContainer == null)
            {
                return;
            }

            targetContainer.Focus();

            ItemsControlUtil.ScrollItemIntoView <ComboBoxItem>(this, PART_ScrollViewer, targetContainer);
        }
コード例 #2
0
        /// <summary>
        /// Selects the item which currently has keyboard focus.
        /// </summary>
        private void SelectFocusedItem()
        {
            var container = ItemsControlUtil.FindFocusedContainer <ComboBoxItem>(this);

            SelectedIndex = (container == null) ? -1 : ItemContainers.IndexOf(container);
        }