tags:

views:

30

answers:

1

I'm struggling a bit with keyboard navigation in the Telerik WPF RadCarousel. If i click outside an item, but within the carousel-control, keyboard naviation works as expected (I can switch between items using the left and right keyboard arrows), but if I click an item within the RadCarousel, keyboard navigation is gone. How can I get the RadCarousel to handle keyboard navigation when an item in the carousel has focus?

Additional things I want to accomplish:

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

My RadCarousel binding is set up as follows:

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

Edit:

By using Snoop, I can see that the "CarouselScrollViewer" has focus when the scrolling is working. Selecting an item causes the RadCarousel to get focus (and the navigation to stop working).

A: 

I got the most import things to work, which was the keyboard navigation and moving the selected item to the front of the carousel.

  1. Keyboard navigation:

    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. Moving selected item into center of carousel:

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