我在Telerik WPF RadCarousel的键盘导航方面有点挣扎。如果我在项目外单击,但在旋转木马控件内,键盘导航按预期工作(我可以使用左右键盘箭头在项目之间切换),但如果我单击RadCarousel中的项目,键盘导航将消失。当旋转木马中的项目具有焦点时,如何让RadCarousel处理键盘导航?
我想要完成的其他事情:
我的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获得焦点(并导航停止工作)。
答案 0 :(得分:0)
我获得了最重要的工作,即键盘导航并将所选项目移动到旋转木马的前面。
键盘导航:
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 < 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<T>(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 && 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;
}
将所选项目移动到轮播中心:
scrollViewer.Focus();