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:
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
0
Accepted
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.
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
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
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.
I am attaching sample project which demonstrates this approach.
Regards,
Dinko
Progress Telerik
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.