This is a migrated thread and some comments may be shown as answers.

Selection using arrow keys

2 Answers 114 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Magnus
Top achievements
Rank 1
Magnus asked on 22 Mar 2017, 08:28 AM
Is it possible to prevent selection with the arrow keys? Whenever I press an arrow key the selected date change, but I would prefer if the selection wasn't changed until I confirm with Enter (which makes the popup close). I'm binding to SelectedDate and tried to set the UpdateSourceTrigger to LostFocus, but that didn't work.

2 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 27 Mar 2017, 07:27 AM
Hi Magnus,

You can try setting the binding to the underlying property with mode = OneTime and eventually manually update it on the DropDownClosed event of the RadDatePicker. For example, if the scenario you have is a RadDateTimePicker in a cell of RadGridView:

private void RadDatePicker_DropDownClosed(object sender, RoutedEventArgs e)
       {
           ((sender as RadDateTimePicker).ParentOfType<GridViewRow>().Item as Club).Established = (sender as RadDateTimePicker).SelectedDate;
       }

Would this work for you?

Regards,
Stefan Nenchev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Magnus
Top achievements
Rank 1
answered on 27 Mar 2017, 08:46 AM

Hi, I solved it by creating a custom RadDatePicker control and adding a dependencyproperty called "ConfirmedSelectedDate" which I don't update when the dropdown is open.

 

//The SelectedConfirmedDate property. Same as SelectedDate, but not updated when DropDown is open
public static readonly DependencyProperty SelectedConfirmedDateProperty = DependencyProperty.Register("SelectedConfirmedDate", typeof(DateTime?), typeof(MyDatePicker));
 
public MyDatePicker()
{
  SelectionChanged += OnSelectionChanged;
  DropDownClosed += OnDropDownClosed;
}
 
private void OnDropDownClosed(object sender, RoutedEventArgs routedEventArgs)
{
  // Update the confirmed selected date when closing dropdown
  SelectedConfirmedDate = SelectedDate;
}
 
private void OnSelectionChanged(object sender, SelectionChangedEventArgs args)
{
  if (IsDropDownOpen)
  {
    // The confirmed date should not update when dropdown is open
    return;
  }
 
  this.SelectedConfirmedDate = this.SelectedDate;
}
Tags
DatePicker
Asked by
Magnus
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Magnus
Top achievements
Rank 1
Share this question
or