New to Telerik UI for WPF? Download free 30-day trial

NavigationBehavior

RadScheduleView's NavigationBehavior is responsible for handling the keyboard navigation. The control handles the KeyDown event for the following keys: Tab, PageUp, PageDown, Home, End and all of the arrow keys. The default navigation logic of the control is implemented in the DefaultNavigationBehavior class.

Implementing Custom NavigationBehavior

In order to modify the default NavigationBehavior of the control, you can create a class inheriting DefaultNavigationBehavior. It exposes a single virtual method - Navigate, which is called when one of the navigation keys is pressed. This method receives NavigationData and NavigationDirection parameters. The NavigationData class exposes a property of type ServiceProvider through which you can get information that you might need (such as selected slots and appointments). Example 1 demonstrates how you can prevent the navigation in some scenarios and use the SlotSelectionService.

Example 1: Custom NavigationBehavior

public class CustomNavigationBehavior : DefaultNavigationBehavior 
{ 
    public override void Navigate(NavigationData data, NavigationDirection direction) 
    { 
        // Prevent navigation for the Home key 
        if (direction == NavigationDirection.First) 
        { 
            return; 
        } 
        // Prevent navigation for the End key 
        else if (direction == NavigationDirection.Last) 
        { 
            return; 
        } 
 
         var slotSelectionService = data.ServiceProvider.GetService<SlotSelectionService>(); 
        var currentSlot = slotSelectionService.GetSelection(); 
 
         if(currentSlot != null) 
        { 
            // Prevent navigation to the right, if we have selected the slot for 24th of September 
            if(currentSlot.End.Month == 9 && currentSlot.End.Day == 24 && direction == NavigationDirection.Right) 
            { 
                return; 
            } 
        } 
 
         base.Navigate(data, direction); 
    } 
} 
Public Class CustomNavigationBehavior 
    Inherits DefaultNavigationBehavior 
 
         Public Overrides Sub Navigate(ByVal data As NavigationData, ByVal direction As NavigationDirection) 
            ' Prevent navigation for the Home key 
            If direction Is NavigationDirection.First Then 
                Return 
            ' Prevent navigation for the End key 
            ElseIf direction Is NavigationDirection.Last Then 
                Return 
            End If 
 
             Dim slotSelectionService = data.ServiceProvider.GetService(Of SlotSelectionService)() 
            Dim currentSlot = slotSelectionService.GetSelection() 
 
             If currentSlot IsNot Nothing Then 
                ' Prevent navigation to the right, if we have selected the slot for 24th of September 
                If currentSlot.End.Month = 9 AndAlso currentSlot.End.Day = 24 AndAlso direction Is NavigationDirection.Right Then 
                    Return 
                End If 
            End If 
 
             MyBase.Navigate(data, direction) 
        End Sub 
End Class 

Example 2: Applying the custom NavigationBehavior

<telerik:RadScheduleView> 
    <telerik:RadScheduleView.NavigationBehavior> 
        <!-- The namespace "local" refers to the namespace where the CustomNavigationBehavior is defined --> 
        <local:CustomNavigationBehavior /> 
    </telerik:RadScheduleView.NavigationBehavior> 
</telerik:RadScheduleView> 

See Also

In this article