0

So basically I have two Textboxes: LoginEmail and LoginPassword. I am trying to set animation for them:

  • User enter LoginEmail #1 animation #1 starts, user quit LoginEmail #1 animation #2 starts
  • User enter LoginEmail #1 animation #1 starts, user quit LoginEmail #1 and go LoginPassword #2 there is no animation

Code

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:

  • LoginEmail_GotFocus (=> FocusAnimation.Begin();)
  • LoginEmail_LostFocus (=> UnfocusAnimation.Begin();)
  • LoginPassword_GotFocus (=> FocusAnimation.Begin();)

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.

Community
  • 1
  • 1
boski
  • 1,106
  • 3
  • 21
  • 44
  • The question is not clear. The identifiers in the code don't match the identifiers in the text of the question (Textbox #1, LoginPassword, ...) You should also provide enough code to reproduce your problem. – madd0 Oct 21 '14 at 11:17
  • Ok. Sorry I just updated my question. – boski Oct 21 '14 at 11:31
  • you're still not providing enough code to reproduce the problem... – madd0 Oct 21 '14 at 12:26
  • You can use any animation that you want. The problem is not animation, but that now I have lost focus event bind to animation, but sometimes that animation shouldn't be fired. So I need a better solution for that to avoid animation when user is selecting LoginPassword from LoginEmail. – boski Oct 21 '14 at 14:06

2 Answers2

1

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();            
      }
}
0

You could simply get the focus for your Textbox1 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?

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82