5
I have several events of my textbox, the problem is that I have about 30 in my form. I wonder if there is any way for me to improve my code, reduce it by creating only one method to control all these events.
Three sample Textbox events:
private void textEmpPrefixo_KeyUp(object sender, KeyEventArgs e)
{
var elemento = e.OriginalSource as UIElement;
if (e.Key == Key.Down)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
if (e.Key == Key.Up)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
private void textEmpTelefones_KeyUp(object sender, KeyEventArgs e)
{
var elemento = e.OriginalSource as UIElement;
if (e.Key == Key.Down)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
if (e.Key == Key.Up)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
private void textEmpObs2_KeyUp(object sender, KeyEventArgs e)
{
var elemento = e.OriginalSource as UIElement;
if (e.Key == Key.Down)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
}
if (e.Key == Key.Up)
{
elemento.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous));
}
}
I use them to shift focus as they use the arrow either up or down I use c# wpf technology.
Thank you in advance (:
Thanks friend, it worked. In case I am applying in the MVVM standard, this method would be in the View same ne?
– Emerson
If the answer helped you, mark it as a sure thing!
– MeuChapeu
@Emerson, stay in the
view
, in the case atcodebehind
of the archive.xml
.– MeuChapeu
Thanks. I just can’t make the answer useful because I need 15 of reputation..
– Emerson
Just a small note on terminology: the method
MudarFoco_keyUp
is not an event - is an Event Handler.KeyUp
is an event.– dcastro
Okay buddy... Blz ^^
– Emerson