当我按下默认键(输入)时,我希望我的按钮具有按下并释放效果(模拟鼠标按下)。
我试过这样做
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
VisualStateManager.GoToState(btnLogin, "Pressed", true);
System.Threading.Thread.Sleep(300);
VisualStateManager.GoToState(btnLogin, "Normal", true);
btnLogin_Click(sender, e);
}
}
无法让它发挥作用。
答案 0 :(得分:0)
你做了按钮Property IsDefault = True
答案 1 :(得分:0)
尝试以下方法 “
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
VisualStateManager.GoToState(btnLogin, "Pressed", true);
this.Refresh();
System.Threading.Thread.Sleep(300);
VisualStateManager.GoToState(btnLogin, "Normal", true);
this.Refresh();
btnLogin_Click(sender, e);
}
}