I need to achieve switching from textbox to textbox, button to textbox etc by pressing enter so I am wondering is there some simple way to do this, like it is WIN FORM, change property like priority 1,2,3,4 and as user pressing enter controls will be switched by numbers from lower to higher.
In wpf I couldn't find that solution but I found this, so I am wondering is it OK?!
Here is my code:
private void Grid_PreviewKeyDown_1(object sender, KeyEventArgs e)
{
try
{
if (e.Key == Key.Enter)
{
TextBox s = e.Source as TextBox;
if (s != null)
{
s.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
else
{
ComboBox cb = e.Source as ComboBox;
if (cb != null)
{
cb.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
else
{
Button b = e.Source as Button;
if (b != null)
{
b.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
}
}
e.Handled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
My controls are contained in Grid.
Thanks guys Cheers!