2

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?

Jamey McElveen
  • 18,135
  • 25
  • 89
  • 129

4 Answers4

12

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...
    }
}
Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
  • Hi Matt, would you mind helping me, I have the same scenario my code is exactly the same as what you answered here, however I do not have a Key.Enter option? – Bohrend Aug 16 '13 at 06:49
  • @user2042227 you're probably missing inclusion of the appropriate namespace (`using System.Windows.Input;`). – Matt Lacey Sep 03 '13 at 13:32
4

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...
}
Derek Lakin
  • 16,179
  • 36
  • 51
0

For Windows Phone 8.1 Apps (not Silverlight) you may use VirtualKey

if (e.Key == Windows.System.VirtualKey.Enter)
{
    //Do Something.
}
Roberto Orozco
  • 579
  • 7
  • 11
0

Do you mean the hardware search button? It's not exposed. Similar question

Community
  • 1
  • 1
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108