所以基本上我有两个Textbox:LoginEmail和LoginPassword。我正在尝试为它们设置动画:
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();
}
它现在无法正常工作,因为当用户输入LoginEmail#1然后转到LoginPassword#2时会有以下事件:
因此有必要弄清楚用户是从LoginEmail转到LoginPassword并且没有显示UnfocusAnimation&第二焦点动画。不幸的是,我不知道如何做到这一点。
答案 0 :(得分:1)
您应该在LoginEmail TextBox之后检查谁获得焦点。 这样的事情应该有效:
private void LoginEmail_LostFocus(object sender, RoutedEventArgs e)
{
var focusedControl = FocusManager.GetFocusedElement(this);
if (focusedControl.GetType() != typeof(TextBox) || ((TextBox)focusedControl).Name != "LoginPassword")
{
UnfocusAnimation.Begin();
}
}
答案 1 :(得分:0)
只要在Textbox
按下任何键,就可以获得keyboard
1的焦点:
yourtextbox.Focus();
然后失去focus
你可以使用这样的东西:
this.Focus();
详细了解这些内容: