Reputation: 1146
So basically I have two Textboxes: LoginEmail and LoginPassword. I am trying to set animation for them:
private void LoginEmail_GotFocus(object sender, RoutedEventArgs e)
{
FocusAnimation.Begin();
}
private void LoginEmail_LostFocus(object sender, RoutedEventArgs e)
{
UnfocusAnimation.Begin();
}
private void LoginPassword_GotFocus(object sender, RoutedEventArgs e)
{
FocusAnimation.Begin();
}
private void LoginPassword_LostFocus(object sender, RoutedEventArgs e)
{
UnfocusAnimation.Begin();
}
It's now not working, because when user enter LoginEmail #1 and then go to LoginPassword #2 there are events:
So there is necessary to figure out that user is going from LoginEmail to LoginPassword and not showing UnfocusAnimation & 2nd FocusAnimation. Unfortunately I don't know the way to do it.
Upvotes: 0
Views: 91
Reputation: 311
You should check who gets the focus after the LoginEmail TextBox. Something like that should work:
private void LoginEmail_LostFocus(object sender, RoutedEventArgs e)
{
var focusedControl = FocusManager.GetFocusedElement(this);
if (focusedControl.GetType() != typeof(TextBox) || ((TextBox)focusedControl).Name != "LoginPassword")
{
UnfocusAnimation.Begin();
}
}
Upvotes: 1
Reputation: 9434
You could simply get the focus for your Textbox
1 whenever any key is being pressed in the keyboard
like :
yourtextbox.Focus();
and then for losing the focus
you can use something like this:
this.Focus();
Have a look at these for more:
https://stackoverflow.com/questions/
How to remove the focus from a TextBox in WinForms?
Upvotes: 0