2011-01-12 38 views

回答

12

InputScope設置爲「搜索」時,「搜索」按鈕只是一個重新設置的「回車」按鈕。因此,假設:

<TextBox InputScope="Search" KeyDown="SearchBox_KeyDown" /> 

「搜索」被按下按鈕(SIP)可以被檢測:

private void SearchBox_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.Key == Key.Enter) 
    { 
     // Do search... 
    } 
} 
+0

嗨馬特搜索按鈕,你能不能幫我,我有相同的場景,我的代碼和你在這裏回答的完全一樣,但是我沒有Key.Enter選項? – Bohrend 2013-08-16 06:49:27

+0

@ user2042227你可能錯過了包含適當的命名空間(`使用System.Windows.Input;`)。 – 2013-09-03 13:32:46

0

你的意思是硬件搜索按鈕?它沒有暴露。 Similar question

+1

問題是指在InputScope,而不是硬件按鈕 – 2011-01-12 10:31:34

4

除了什麼太有(正確)回答,如果你處理收到.PlatformKeyCode == 0x0A(如下圖所示),您也可以在沒有SIP的模擬器中運行時響應在主機鍵盤上按下的Enter鍵。

if ((Key.Enter == e.Key) || (e.PlatformKeyCode == 0x0A)) 
{ 
    // Do search... 
} 
0

對於Windows Phone的8.1應用程序(不Silverlight的),你可以使用VirtualKey

if (e.Key == Windows.System.VirtualKey.Enter) 
{ 
    //Do Something. 
} 
相關問題