当前位置: 首页>>代码示例>>C#>>正文


C# FocusNavigationDirection类代码示例

本文整理汇总了C#中FocusNavigationDirection的典型用法代码示例。如果您正苦于以下问题:C# FocusNavigationDirection类的具体用法?C# FocusNavigationDirection怎么用?C# FocusNavigationDirection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FocusNavigationDirection类属于命名空间,在下文中一共展示了FocusNavigationDirection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MoveFocus

        public static bool MoveFocus([CanBeNull] DependencyObject element, FocusNavigationDirection direction = FocusNavigationDirection.Next) {
            var e = element as UIElement;
            if (e == null) return false;

            e.MoveFocus(new TraversalRequest(direction));
            return true;
        }
开发者ID:gro-ove,项目名称:actools,代码行数:7,代码来源:FocusAdvancement.cs

示例2: GetNext

        /// <summary>
        /// Gets the next control in the specified navigation direction.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="direction">The navigation direction.</param>
        /// <returns>
        /// The next element in the specified direction, or null if <paramref name="element"/>
        /// was the last in the requested direction.
        /// </returns>
        public static IInputElement GetNext(
            IInputElement element,
            FocusNavigationDirection direction)
        {
            Contract.Requires<ArgumentNullException>(element != null);
            Contract.Requires<ArgumentException>(
                direction != FocusNavigationDirection.Next &&
                direction != FocusNavigationDirection.Previous);

            var container = element.GetVisualParent<IInputElement>();

            if (container != null)
            {
                var isForward = IsForward(direction);
                var mode = KeyboardNavigation.GetDirectionalNavigation((InputElement)container);

                switch (mode)
                {
                    case KeyboardNavigationMode.Continue:
                        return GetNextInContainer(element, container, direction) ??
                               GetFirstInNextContainer(element, direction);
                    case KeyboardNavigationMode.Cycle:
                        return GetNextInContainer(element, container, direction) ??
                               GetFocusableDescendent(container, direction);
                    case KeyboardNavigationMode.Contained:
                        return GetNextInContainer(element, container, direction);
                    default:
                        return null;
                }
            }
            else
            {
                return GetFocusableDescendents(element).FirstOrDefault();
            }
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:44,代码来源:DirectionalNavigation.cs

示例3: IsForward

 /// <summary>
 /// Returns a value indicting whether the specified direction is forward.
 /// </summary>
 /// <param name="direction">The direction.</param>
 /// <returns>True if the direction is forward.</returns>
 private static bool IsForward(FocusNavigationDirection direction)
 {
     return direction == FocusNavigationDirection.Next ||
            direction == FocusNavigationDirection.Last ||
            direction == FocusNavigationDirection.Right ||
            direction == FocusNavigationDirection.Down;
 }
开发者ID:rdterner,项目名称:Perspex,代码行数:12,代码来源:DirectionalNavigation.cs

示例4: GetFirstInNextContainer

        /// <summary>
        /// Gets the first item that should be focused in the next container.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="direction">The direction of the search.</param>
        /// <returns>The first element, or null if there are no more elements.</returns>
        private static IInputElement GetFirstInNextContainer(
            IInputElement container,
            FocusNavigationDirection direction)
        {
            var parent = container.GetVisualParent<IInputElement>();
            var isForward = IsForward(direction);
            IInputElement next = null;

            if (parent != null)
            {
                if (!isForward && parent.CanFocus())
                {
                    return parent;
                }

                var siblings = parent.GetVisualChildren()
                    .OfType<IInputElement>()
                    .Where(FocusExtensions.CanFocusDescendents);
                IInputElement sibling;

                if (isForward)
                {
                    sibling = siblings.SkipWhile(x => x != container).Skip(1).FirstOrDefault();
                }
                else
                {
                    sibling = siblings.TakeWhile(x => x != container).LastOrDefault();
                }

                if (sibling != null)
                {
                    if (sibling.CanFocus())
                    {
                        next = sibling;
                    }
                    else
                    {
                        next = isForward ?
                            GetFocusableDescendents(sibling).FirstOrDefault() :
                            GetFocusableDescendents(sibling).LastOrDefault();
                    }
                }

                if (next == null)
                {
                    next = GetFirstInNextContainer(parent, direction);
                }
            }
            else
            {
                next = isForward ?
                    GetFocusableDescendents(container).FirstOrDefault() :
                    GetFocusableDescendents(container).LastOrDefault();
            }

            return next;
        }
开发者ID:Scellow,项目名称:Perspex,代码行数:63,代码来源:DirectionalNavigation.cs

示例5: QueryMoveFocusEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="QueryMoveFocusEventArgs"/> class.
        /// </summary>
        /// <param name="pDirection">The focus direction.</param>
        /// <param name="pReachedMaxLength">Flag indicating if the text maximum length has been reached.</param>
        internal QueryMoveFocusEventArgs(FocusNavigationDirection pDirection, bool pReachedMaxLength)
            : base(AutoSelectTextBox.QueryMoveFocusEvent)
        {
            // Internal to prevent anybody from building this type of event.
            this.FocusNavigationDirection = pDirection;
            this.ReachedMaxLength = pReachedMaxLength;

            // Defaults to true. If nobody does nothing, then its capable of moving focus.
            this.CanMoveFocus = true;
        }
开发者ID:mastertnt,项目名称:XRay,代码行数:15,代码来源:QueryMoveFocusEventArgs.cs

示例6: MoveSelection

        protected virtual void MoveSelection(FocusNavigationDirection direction)
        {
            // TODO: Up and down movement is a *HACK* and probably pretty slow. Probably needs
            // rewriting at some point.
            if (this.SelectedItem != null)
            {
                switch (direction)
                {
                    case FocusNavigationDirection.Up:
                        {
                            var list = this.Flatten();
                            var index = list.IndexOf(this.SelectedItem);

                            if (index > 0)
                            {
                                this.SelectedItem = list[index - 1];
                            }

                            break;
                        }

                    case FocusNavigationDirection.Down:
                        {
                            var list = this.Flatten();
                            var index = list.IndexOf(this.SelectedItem);

                            if (index + 1 < list.Count)
                            {
                                this.SelectedItem = list[index + 1];
                            }

                            break;
                        }

                    case FocusNavigationDirection.Left:
                        {
                            var node = (TreeViewItem)this.ItemContainerGenerator.GetContainerForItem(this.SelectedItem);
                            node.IsExpanded = false;
                            break;
                        }

                    case FocusNavigationDirection.Right:
                        {
                            var node = (TreeViewItem)this.ItemContainerGenerator.GetContainerForItem(this.SelectedItem);
                            node.IsExpanded = true;
                            break;
                        }
                }
            }
        }
开发者ID:MarkWalls,项目名称:Perspex,代码行数:50,代码来源:TreeView.cs

示例7: Move

        /// <summary>
        /// Moves the focus in the specified direction.
        /// </summary>
        /// <param name="element">The current element.</param>
        /// <param name="direction">The direction to move.</param>
        public void Move(IInputElement element, FocusNavigationDirection direction)
        {
            Contract.Requires<ArgumentNullException>(element != null);

            var next = GetNext(element, direction);

            if (next != null)
            {
                var method = direction == FocusNavigationDirection.Next ||
                             direction == FocusNavigationDirection.Previous ?
                             NavigationMethod.Tab : NavigationMethod.Directional;
                FocusManager.Instance.Focus(next, method);
            }
        }
开发者ID:healtech,项目名称:Perspex,代码行数:19,代码来源:KeyboardNavigationHandler.cs

示例8: PredictFocus

        internal static DependencyObject PredictFocus(DependencyObject o, FocusNavigationDirection direction)
        {
            Debug.Assert(o != null, "UIElementHelper.PredictFocus called with null argument");

            UIElement oAsUIElement = o as UIElement;
            if (oAsUIElement != null)
            {
                return oAsUIElement.PredictFocus(direction);
            }
            else
            {
                return ((UIElement3D)o).PredictFocus(direction);
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:14,代码来源:UIElementHelper.cs

示例9: GetNext

        /// <summary>
        /// Gets the next control in the specified navigation direction.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="direction">The navigation direction.</param>
        /// <returns>
        /// The next element in the specified direction, or null if <paramref name="element"/>
        /// was the last in therequested direction.
        /// </returns>
        public static IInputElement GetNext(
            IInputElement element,
            FocusNavigationDirection direction)
        {
            Contract.Requires<ArgumentNullException>(element != null);

            if (direction == FocusNavigationDirection.Next || direction == FocusNavigationDirection.Previous)
            {
                return TabNavigation.GetNextInTabOrder(element, direction);
            }
            else
            {
                return DirectionalNavigation.GetNext(element, direction);
            }
        }
开发者ID:healtech,项目名称:Perspex,代码行数:24,代码来源:KeyboardNavigationHandler.cs

示例10: TraversalRequest

        /// <summary>
        /// Constructor that requests passing FocusNavigationDirection
        /// </summary>
        /// <param name="focusNavigationDirection">Type of focus traversal to perform</param>
        public TraversalRequest(FocusNavigationDirection focusNavigationDirection)
        {
            if (focusNavigationDirection != FocusNavigationDirection.Next &&
                 focusNavigationDirection != FocusNavigationDirection.Previous &&
                 focusNavigationDirection != FocusNavigationDirection.First &&
                 focusNavigationDirection != FocusNavigationDirection.Last &&
                 focusNavigationDirection != FocusNavigationDirection.Left &&
                 focusNavigationDirection != FocusNavigationDirection.Right &&
                 focusNavigationDirection != FocusNavigationDirection.Up &&
                 focusNavigationDirection != FocusNavigationDirection.Down)
            {
                throw new System.ComponentModel.InvalidEnumArgumentException("focusNavigationDirection", (int)focusNavigationDirection, typeof(FocusNavigationDirection));
            }

            _focusNavigationDirection = focusNavigationDirection;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:20,代码来源:TraversalRequest.cs

示例11: MoveFocus

        /// <summary>
        /// 指定の方向にある Control へフォーカスの設定を試みます。
        /// </summary>
        /// <param name="direction">フォーカスの移動方向。</param>
        /// <returns>
        /// true (フォーカスの設定に成功した場合)、false (それ以外の場合)。
        /// </returns>
        public bool MoveFocus(FocusNavigationDirection direction)
        {
            var next = owner.GetFocusableControl(direction, FocusNavigationMode);
            if (next == null) return false;

            var result = MoveFocusTo(next);

            if (result)
            {
                var sound = owner.Screen.GetSound(SoundKey.FocusNavigation);
                if (sound != null)
                {
                    if (sound.State != SoundState.Stopped) sound.Stop();
                    sound.Play();
                }
            }

            return result;
        }
开发者ID:willcraftia,项目名称:Blocks,代码行数:26,代码来源:FocusScope.cs

示例12: switch

        /// <summary>
        /// Gets the next control in the specified direction.
        /// </summary>
        /// <param name="direction">The movement direction.</param>
        /// <param name="from">The control from which movement begins.</param>
        /// <returns>The control.</returns>
        IInputElement INavigableContainer.GetControl(FocusNavigationDirection direction, IInputElement from)
        {
            var horiz = Orientation == Orientation.Horizontal;
            int index = Children.IndexOf((IControl)from);

            switch (direction)
            {
                case FocusNavigationDirection.First:
                    index = 0;
                    break;
                case FocusNavigationDirection.Last:
                    index = Children.Count - 1;
                    break;
                case FocusNavigationDirection.Next:
                    ++index;
                    break;
                case FocusNavigationDirection.Previous:
                    --index;
                    break;
                case FocusNavigationDirection.Left:
                    index = horiz ? index - 1 : -1;
                    break;
                case FocusNavigationDirection.Right:
                    index = horiz ? index + 1 : -1;
                    break;
                case FocusNavigationDirection.Up:
                    index = horiz ? -1 : index - 1;
                    break;
                case FocusNavigationDirection.Down:
                    index = horiz ? -1 : index + 1;
                    break;
            }

            if (index >= 0 && index < Children.Count)
            {
                return Children[index];
            }
            else
            {
                return null;
            }
        }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:48,代码来源:StackPanel.cs

示例13: switch

        Control INavigablePanel.GetControl(FocusNavigationDirection direction, Control from)
        {
            var horiz = this.Orientation == Orientation.Horizontal;
            int index = this.Children.IndexOf(from);

            switch (direction)
            {
                case FocusNavigationDirection.First:
                    index = 0;
                    break;
                case FocusNavigationDirection.Last:
                    index = this.Children.Count - 1;
                    break;
                case FocusNavigationDirection.Next:
                    ++index;
                    break;
                case FocusNavigationDirection.Previous:
                    ++index;
                    break;
                case FocusNavigationDirection.Left:
                    index = horiz ? index - 1 : -1;
                    break;
                case FocusNavigationDirection.Right:
                    index = horiz ? index + 1 : -1;
                    break;
                case FocusNavigationDirection.Up:
                    index = horiz ? -1 : index - 1;
                    break;
                case FocusNavigationDirection.Down:
                    index = horiz ? -1 : index + 1;
                    break;
            }

            if (index >= 0 && index < this.Children.Count)
            {
                return this.Children[index];
            }
            else
            {
                return null;
            }
        }
开发者ID:MarkWalls,项目名称:Perspex,代码行数:42,代码来源:StackPanel.cs

示例14: GetNextInContainer

        /// <summary>
        /// Gets the next item that should be focused in the specified container.
        /// </summary>
        /// <param name="element">The starting element/</param>
        /// <param name="container">The container.</param>
        /// <param name="direction">The direction.</param>
        /// <returns>The next element, or null if the element is the last.</returns>
        private static IInputElement GetNextInContainer(
            IInputElement element,
            IInputElement container,
            FocusNavigationDirection direction)
        {
            if (direction == FocusNavigationDirection.Down)
            {
                var descendent = GetFocusableDescendents(element).FirstOrDefault();

                if (descendent != null)
                {
                    return descendent;
                }
            }

            if (container != null)
            {
                var navigable = container as INavigableContainer;

                if (navigable != null)
                {
                    while (element != null)
                    {
                        element = navigable.GetControl(direction, element);

                        if (element != null && element.CanFocus())
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // TODO: Do a spatial search here if the container doesn't implement
                    // INavigableContainer.
                    element = null;
                }

                if (element != null && direction == FocusNavigationDirection.Up)
                {
                    var descendent = GetFocusableDescendents(element).LastOrDefault();

                    if (descendent != null)
                    {
                        return descendent;
                    }
                }

                return element;
            }

            return null;
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:60,代码来源:DirectionalNavigation.cs

示例15: InternalPredictFocus

        /// <summary> 
        /// This should be PredictFocus but since UIElement.PredictFocus is sealed by FE we can't override it.
        /// TreeViewItem has its own code for deciding where focus should go. 
        /// </summary>
        /// <param name="direction"></param>
        /// <returns></returns>
        internal DependencyObject InternalPredictFocus(FocusNavigationDirection direction) 
        {
            switch (direction) 
            { 
                case FocusNavigationDirection.Left:
                case FocusNavigationDirection.Up: 
                    return FindPreviousFocusableItem();
                case FocusNavigationDirection.Right:
                case FocusNavigationDirection.Down:
                    return FindNextFocusableItem(true); 
                default:
                    return null; 
            } 

        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:21,代码来源:TreeViewItem.cs


注:本文中的FocusNavigationDirection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。