2012-04-27 171 views
0

當我按下我的默認鍵(輸入)時,我希望我的按鈕具有按下並釋放的效果(模擬鼠標按下)。當按下默認鍵時顯示按鈕按下效果

我試圖這樣做

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

你做你的按鈕物業ISDEFAULT =真

+0

是我沒有使用ISDEFAULT =真 – deception1 2012-04-27 09:31:51

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

+0

我有什麼要添加到使用此.Refresh(); AFAIK在WPF中沒有Refresh() – deception1 2012-04-27 09:31:21

+0

我想穿過的是即使按鈕的狀態正在改變,它也沒有被繪製。刷新繪製屏幕上的Windows窗體應用程序的控件,因此我認爲同樣的情況在這裏.... – kingpin 2012-04-27 09:58:50

相關問題