Articles in this section

How to change the date using up or down navigation keys in WPF DatePicker (SfDatePicker)?

WPF DatePicker (SfDatePicker) control does not direct option to change date using up or down navigation keys. It can be achieved by handling PopupOpened event and enabling SetValueOnLostFocus property in WPF DatePicker (SfDatePicker). The following code demonstrates the same.

XAML

<sf:SfDatePicker x:Name="MonthDatePicker" SetValueOnLostFocus="True" Focusable="True" />

C#

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
  // SfDateSelector
  SfDateSelector selector = null;
  // Popup
  Popup popUp;
 
  public MainWindow()
  {
    InitializeComponent();
    this.MonthDatePicker.Loaded += MonthDatePicker_Loaded;
  }
 
  /// <summary>
  /// Invoked when SfDatePicker Loaded
  /// </summary>
  private void MonthDatePicker_Loaded(object sender, RoutedEventArgs e)
  {
    popUp = MonthDatePicker.Template.FindName("PART_DropDown", MonthDatePicker) as Popup;
    selector = MonthDatePicker.Template.FindName("PART_DateSelector", MonthDatePicker) as SfDateSelector;
    if (popUp != null)
    {
      popUp.Opened += PopUp_Opened;
    }
  }
 
  /// <summary>
  /// Invoked when the popup opened
  /// </summary>
  private void PopUp_Opened(object sender, EventArgs e)
  {
    Keyboard.Focus(selector);
  }
}

 

Note:

Tab key can be used to navigate between the Day, Month and Year fields in SfDateSeletor.

View sample in GitHub.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied