English 中文(简体)
Telerik WPF RadCarousel中的键盘导航
原标题:Keyboard navigation in Telerik WPF RadCarousel
  • 时间:2010-10-15 12:42:08
  •  标签:
  • wpf
  • telerik

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

我想完成的其他事情:

  1. Automatically show the SelectedItem as the "front-item" in the carousel.
  2. Automatically select the "front-item" when navigating through the carousel.

我的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获得焦点(并使导航停止工作)。

最佳回答

我得到了最重要的工作,那就是键盘导航和将所选项目移动到旋转木马的前面。

  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);
    }
    
问题回答

暂无回答




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签