Tab on Enter Key

5 posts, 1 answers
  1. Vic
    Vic avatar
    36 posts
    Member since:
    Aug 2012

    Posted 28 Aug 2012 Link to this post

    Hello,
    I'm trying to get the NumericUpDown to tab to the next control when the user presses Enter.  Handling the KeyUp or KeyDown event with the following code does not work: 
    (sender as RadNumericUpDown).MoveFocus(new TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next));
    e.Handled = true;

    Any suggestions?

     

     



  2. Answer
    Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 03 Sep 2012 Link to this post

    Hi,

    We reproduced this behavior at our side. We will do our best to fix it for one of our future releases. There is an easy workaround for it. If you get the TextBox part of the RadNumericUpDown and call MoveFocus to it this will work as expected.
    var numericUpDown = (RadNumericUpDown)sender;
    var textBox = numericUpDown.ChildrenOfType<TextBox>().FirstOrDefault();
    textBox.MoveFocus(new TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next));
    e.Handled = true;

    We don't usually recommend using ChildrenOfType extension method, but at this case you can call it only once into the RadNumericUpDown's Loaded event and store the found TextBox into a variable. This way the workaround will not affect the performance of your application.

    Regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Vic
    Vic avatar
    36 posts
    Member since:
    Aug 2012

    Posted 03 Sep 2012 Link to this post

    Thank you, Ivo.  The work around works fine.
  4. Joel
    Joel avatar
    112 posts
    Member since:
    Sep 2013

    Posted 28 Feb 2018 Link to this post

    While i know this is about NumericUpDown, i am just wondering does the same bug also appear in RadMaskedNumericInput? 
    I am using telerik wpf 2017.1.117.40

    Here is my attach property to listen to the Enter key down event. The MoveFocus() method is not working out for me.

    I have also set AcceptsReturn to False.

    static void Keydown(object sender, KeyEventArgs e)
    {
        if (!e.Key.Equals(Key.Enter)) return;
        var element = sender as UIElement;
        if (element != null) element.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
    }
  5. Dinko
    Admin
    Dinko avatar
    937 posts

    Posted 05 Mar 2018 Link to this post

    Hello Joel,

    The reason why the code snippet is not working for the RadMaskedInput is that there is a TextBox inside the ControlTemplate of the MaskedInputControls. To work this out you can try the approach in the following code snippet. 
    private void RadMaskedTextInput_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            var tBox = (sender as RadMaskedNumericInput).ChildrenOfType<TextBox>().FirstOrDefault();
            if (tBox != null)
            {
               tBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            }
        }
    }

    I am attaching sample project which demonstrates this approach.

    Regards,
    Dinko
    Progress Telerik
    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.
Back to Top