How can I tell when the “search” button is clicked when I set InputScope to search?
-
10-10-2019 - |
Question
For Windows Phone. How can I tell when the "search" button is clicked when I set InputScope to search on a TextBox? Is there an event?
Solution
When the InputScope
is set to "Search", the "search" button is just a restyled "enter" button. So, assuming:
<TextBox InputScope="Search" KeyDown="SearchBox_KeyDown" />
the "search " button being pressed (on the SIP) can be detected with:
private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
// Do search...
}
}
OTHER TIPS
In addition to what Matt has (correctly) answered, if you handle e.PlatformKeyCode == 0x0A (as shown below) you can also respond to the Enter key being pressed on the host keyboard when running in the emulator without the SIP.
if ((Key.Enter == e.Key) || (e.PlatformKeyCode == 0x0A))
{
// Do search...
}
Do you mean the hardware search button? It's not exposed. Similar question
For Windows Phone 8.1 Apps (not Silverlight) you may use VirtualKey
if (e.Key == Windows.System.VirtualKey.Enter)
{
//Do Something.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow