Keyboardfocus on calendar control

Posted by: lutz.boscher on 13 February 2019, 6:46 pm EST

  • Posted 13 February 2019, 6:46 pm EST

    At startup I want to set the focus to the calendar control in code behind and after that, the user should navigate through the calendar with the keyboard only.

    I have attached a small sample. After clicking the button, the keyboardfocus is set to the calendar, but the calendar does not response to the arrow-keys. First, I have to click in the calendar control to get the keyboardnavigation working.

    What can we do to navigate inside the calendar without using the mouse?

    Lutz Boscher

    Lutz Boscher

  • Replied 13 February 2019, 6:50 pm EST

    The attachemnt was not sent, vwnt thoought it was droped-

    the two files as plain text:
    <Window x:Class="C1Calendar.MainWindow"
    FocusManager.FocusedElement="{Binding ElementName=_cal}"
    Title="MainWindow" Height="450" Width="800" >
    <c1:C1Calendar x:Name="_cal" Focusable="True" GotKeyboardFocus="C1Calendar_GotKeyboardFocus"
    LostKeyboardFocus="C1Calendar_LostKeyboardFocus" Canvas.Left="280" Canvas.Top="120" />
    <Button Content="Set Focus" Click="Button_Click" Canvas.Left="343" Canvas.Top="332" LostKeyboardFocus="Button_LostKeyboardFocus"/>

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Windows.Threading;
    using C1Calendar;

    namespace C1Calendar {
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
    public MainWindow() {

    private void C1Calendar_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {
    Debug.WriteLine("In GotKeyboardFocus");
    _cal.SelectedDate = DateTime.Today;

    private void C1Calendar_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {
    Debug.WriteLine("In LostKeyboardFocus");

    private void Button_Click(object sender, RoutedEventArgs e) {

    var sucess = _cal.Focus();
    var focusedElement = Keyboard.Focus(_cal);
    Debug.WriteLine($"Setting KeyboardFocus to _calendar: {sucess}. Focus has {focusedElement}");

    private void Button_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {
    Debug.WriteLine("In Button_LostFocus");

  • Marked as Answer

    Replied 14 February 2019, 8:55 pm EST

    Hello Lutz,

    For this you need to access the C1CalendarItem present inside C1Calendar and set keyboard focus to it. You may use C1Calendar's PreviewKeyDown event for this
            private void Window_Loaded(object sender, RoutedEventArgs e)
    calItem = FindVisualChildren<C1.WPF.Schedule.C1CalendarItem>(_cal).ToList()[0];
    calItem.Focusable = true;
    private void _cal_PreviewKeyDown(object sender, KeyEventArgs e)
    if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
    UIElement keyboardFocus = calItem as UIElement;
    TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
    if (keyboardFocus != null)

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels