Selection using arrow keys

3 posts, 0 answers
  1. Magnus
    Magnus avatar
    23 posts
    Member since:
    Dec 2011

    Posted 22 Mar Link to this post

    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. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    501 posts

    Posted 27 Mar Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Magnus
    Magnus avatar
    23 posts
    Member since:
    Dec 2011

    Posted 27 Mar in reply to Stefan Nenchev Link to this post

    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;
    }
Back to Top