Reputation: 681
I have a searchbox where the user of my app can type in a word. I would like to be able to click the "Enter" key on the phones keyboard to start the search, but that doesn't work so instead I need to have a button to launch the search function.
<TextBox Name="txtSearchBox" InputScope="Search"/>
How can I make the enter key launch a function?
Thanks in advance.
Upvotes: 0
Views: 2585
Reputation: 1
The suggested answer doesn't work anymore in C#
so here is my code that does work
private void searchbox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
searchButton_Click(this, new EventArgs());
}
}
Upvotes: 0
Reputation: 4178
You can catch the key pressed in the Key_Up event and compare it to the enter
key
private void txtSearchBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
DoSearchHere();
}
Upvotes: 3