【问题标题】:Keyboard navigation in Telerik WPF RadCarouselTelerik WPF RadCarousel 中的键盘导航
【发布时间】:2011-04-25 22:22:03
【问题描述】:

我在 Telerik WPF RadCarousel 中的键盘导航有点吃力。如果我在项目外部单击,但在轮播控件中,键盘导航按预期工作(我可以使用左右键盘箭头在项目之间切换),但如果我单击 RadCarousel 中的项目,键盘导航就消失了。当轮播中的项目具有焦点时,如何让 RadCarousel 处理键盘导航?

我想完成的其他事情:

  1. 自动将 SelectedItem 显示为轮播中的“front-item”。
  2. 在轮播中导航时自动选择“前端项目”。

我的 RadCarousel 绑定设置如下:

    <ScrollViewer CanContentScroll="true">
        <telerik:RadCarousel Name="carousel" HorizontalScrollBarVisibility="Hidden" 
                             ItemsSource="{Binding Path=Templates}"
                             ItemTemplate="{StaticResource template}"
                             SelectedItem="{Binding Path=SelectedTemplateAndFolder}" />
    </ScrollViewer>

编辑:

通过使用 Snoop,我可以看到“CarouselScrollViewer”在滚动工作时具有焦点。选择一个项目会导致 RadCarousel 获得焦点(并且导航停止工作)。

【问题讨论】:

    标签: wpf telerik


    【解决方案1】:

    我得到了最重要的工作,这是键盘导航并将所选项目移动到轮播的前面。

    1. 键盘导航:

      private void Carousel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
      {
          CarouselScrollViewer scrollViewer = FindChild<CarouselScrollViewer>(this.carousel, null);
      
      
      
      scrollViewer.Focus();
      
      } public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject { // Confirm parent and childName are valid. if (parent == null) return null;
      T foundChild = null;
      
      
      int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
      for (int i = 0; i &lt; childrenCount; i++)
      {
          var child = VisualTreeHelper.GetChild(parent, i);
          // If the child is not of the request child type child
          T childType = child as T;
          if (childType == null)
          {
              // recursively drill down the tree
              foundChild = FindChild&lt;T&gt;(child, childName);
      
      
              // If the child is found, break so we do not overwrite the found child. 
              if (foundChild != null) break;
          }
          else if (!string.IsNullOrEmpty(childName))
          {
              var frameworkElement = child as FrameworkElement;
              // If the child's name is set for search
              if (frameworkElement != null &amp;&amp; frameworkElement.Name == childName)
              {
                  // if the child's name is of the request name
                  foundChild = (T)child;
                  break;
              }
          }
          else
          {
              // child element found.
              foundChild = (T)child;
              break;
          }
      }
      
      
      return foundChild;
      
      }
    2. 将所选项目移动到轮播中心:

      private void Carousel_SelectionChanged(object sender, SelectionChangeEventArgs e)
      {
          this.carousel.BringDataItemIntoView(this.carousel.CurrentItem);
      }
      

    【讨论】:

      猜你喜欢
      • 2011-09-05
      • 2012-10-29
      • 2011-01-17
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 2015-08-22
      相关资源
      最近更新 更多