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

Tab on Enter Key

4 Answers 543 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Vic
Top achievements
Rank 1
Iron
Vic asked on 28 Aug 2012, 06:19 PM
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?

 

 



4 Answers, 1 is accepted

Sort by
0
Accepted
Ivo
Telerik team
answered on 03 Sep 2012, 11:50 AM
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.

0
Vic
Top achievements
Rank 1
Iron
answered on 03 Sep 2012, 03:05 PM
Thank you, Ivo.  The work around works fine.
0
Joel
Top achievements
Rank 1
Iron
answered on 01 Mar 2018, 04:51 AM

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));
}
0
Dinko | Tech Support Engineer
Telerik team
answered on 05 Mar 2018, 01:08 PM
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.
Tags
NumericUpDown
Asked by
Vic
Top achievements
Rank 1
Iron
Answers by
Ivo
Telerik team
Vic
Top achievements
Rank 1
Iron
Joel
Top achievements
Rank 1
Iron
Dinko | Tech Support Engineer
Telerik team
Share this question
or