• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# FocusNavigationDirection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: AllowHandleKeyEvent

        private bool AllowHandleKeyEvent(FocusNavigationDirection direction) 
        {
            if (!IsSelected)
            {
                return false; 
            }
 
            DependencyObject currentFocus = Keyboard.FocusedElement as DependencyObject; 
            if (currentFocus != null && UIElementHelper.IsUIElementOrUIElement3D(currentFocus))
            { 
                DependencyObject predict = UIElementHelper.PredictFocus(currentFocus, direction);
                if (predict != currentFocus)
                {
                    while (predict != null) 
                    {
                        TreeViewItem item = predict as TreeViewItem; 
                        if (item == this) 
                        {
                            return false; // There is a focusable item in the header 
                        }
                        else if ((item != null) || (predict is TreeView))
                        {
                            return true; 
                        }
 
                        predict = VisualTreeHelper.GetParent(predict); 
                    }
                } 
            }

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


示例17: PredictFocus

 public static DependencyObject PredictFocus(DependencyObject element, FocusNavigationDirection direction)
 {
     UIElement uie = element as UIElement;
     if (uie != null)
     {
         return uie.PredictFocus(direction);
     }
     ContentElement ce = element as ContentElement;
     if (ce != null)
     {
         return ce.PredictFocus(direction);
     }
     return null;
 }
开发者ID:kasicass,项目名称:kasicass,代码行数:14,代码来源:RibbonHelper.cs


示例18: MoveFocus

 public static bool MoveFocus(FocusNavigationDirection direction)
 {
     UIElement uie = Keyboard.FocusedElement as UIElement;
     if (uie != null)
     {
         return uie.MoveFocus(new TraversalRequest(direction));
     }
     ContentElement ce = Keyboard.FocusedElement as ContentElement;
     if (ce != null)
     {
         return ce.MoveFocus(new TraversalRequest(direction));
     }
     return false;
 }
开发者ID:kasicass,项目名称:kasicass,代码行数:14,代码来源:RibbonHelper.cs


示例19: NavigatePageAndHighlightRibbonGalleryItem

        // This method is called when trying to navigate pages within a RibbonGallery.
        // We approximate the RibbonGalleryItem that is a page away from the currently
        // focused item based upon the precomputed MaxColumnWidth and MaxRowHeight values.
        internal static bool NavigatePageAndHighlightRibbonGalleryItem(
            RibbonGallery gallery,
            RibbonGalleryItem galleryItem,
            FocusNavigationDirection direction,
            out RibbonGalleryItem highlightedGalleryItem)
        {
            highlightedGalleryItem = null;

            RibbonGalleryCategoriesPanel categoriesPanel = gallery.ItemsHostSite as RibbonGalleryCategoriesPanel;
            if (categoriesPanel != null)
            {
                double viewportWidth = categoriesPanel.ViewportWidth;
                double viewportHeight = categoriesPanel.ViewportHeight;

                RibbonGalleryCategory category, prevCategory = null;
                if (galleryItem != null)
                {
                    category = galleryItem.RibbonGalleryCategory;
                }
                else
                {
                    category = gallery.Items.Count > 0 ? gallery.ItemContainerGenerator.ContainerFromIndex(0) as RibbonGalleryCategory : null;
                    galleryItem = category != null && category.Items.Count > 0 ? category.ItemContainerGenerator.ContainerFromIndex(0) as RibbonGalleryItem : null;
                }

                if (category != null)
                {
                    Debug.Assert(category.RibbonGallery == gallery, "The reference RibbongalleryItem and the RibbonGallery must be related.");

                    int startCatIndex = gallery.ItemContainerGenerator.IndexFromContainer(category);
                    int endCatIndex, incr;

                    if (direction == FocusNavigationDirection.Up)
                    {
                        endCatIndex = -1;
                        incr = -1;
                    }
                    else
                    {
                        endCatIndex = gallery.Items.Count;
                        incr = 1;
                    }

                    for (int catIndex = startCatIndex; catIndex != endCatIndex && highlightedGalleryItem == null; catIndex += incr)
                    {
                        category = gallery.ItemContainerGenerator.ContainerFromIndex(catIndex) as RibbonGalleryCategory;
                        RibbonGalleryItemsPanel galleryItemsPanel = category.ItemsHostSite as RibbonGalleryItemsPanel;

                        // We want to skip over filtered categories

                        if (category.Visibility != Visibility.Visible)
                        {
                            continue;
                        }

                        int startItemIndex, endItemIndex, startColumnIndex, endColumnIndex, columnCount;
                        columnCount = (int)(viewportWidth / galleryItemsPanel.MaxColumnWidth);

                        if (direction == FocusNavigationDirection.Up)
                        {
                            startItemIndex = galleryItem != null ? category.ItemContainerGenerator.IndexFromContainer(galleryItem) : category.Items.Count - 1;
                            endItemIndex = -1;

                            if (prevCategory != null)
                            {
                                viewportHeight -= prevCategory.HeaderPresenter.ActualHeight;

                                if (DoubleUtil.LessThanOrClose(viewportHeight, 0))
                                {
                                    highlightedGalleryItem = category.ItemContainerGenerator.ContainerFromIndex(startItemIndex) as RibbonGalleryItem;
                                    break;
                                }
                            }

                            // startColumnIndex is the last column in the last row or the column of the anchor item

                            if (columnCount == 1)
                            {
                                startColumnIndex = 0;
                                endColumnIndex = 0;
                            }
                            else
                            {
                                startColumnIndex = (galleryItem != null ? startItemIndex : category.Items.Count - 1) % columnCount;
                                endColumnIndex = 0;
                            }
                        }
                        else
                        {
                            startItemIndex = galleryItem != null ? category.ItemContainerGenerator.IndexFromContainer(galleryItem) : 0;
                            endItemIndex = category.Items.Count;

                            if (prevCategory != null)
                            {
                                viewportHeight -= category.HeaderPresenter.ActualHeight;

                                if (DoubleUtil.LessThanOrClose(viewportHeight, 0))
//.........这里部分代码省略.........
开发者ID:kasicass,项目名称:kasicass,代码行数:101,代码来源:RibbonHelper.cs


示例20: NavigateAndHighlightGalleryItem

        // This method is called when trying to navigate a single step up, down, left or
        // right within a RibbonGallery.
        internal static bool NavigateAndHighlightGalleryItem(RibbonGalleryItem focusedElement, FocusNavigationDirection direction)
        {
            if (focusedElement != null)
            {
                RibbonGalleryItem predictedFocus = focusedElement.PredictFocus(direction) as RibbonGalleryItem;
                if (predictedFocus != null)
                {
                    predictedFocus.IsHighlighted = true;
                    return true;
                }
            }

            return false;
        }
开发者ID:kasicass,项目名称:kasicass,代码行数:16,代码来源:RibbonHelper.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# FocusedRowChangedEventArgs类代码示例发布时间:2022-05-24
下一篇:
C# FmdcEventArgs类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap