use*_*349 2 c# xaml textbox event-handling windows-phone-8
在我的应用程序中,我有一个文本框,当用户按下键盘上的返回按钮时,它应该有一个文本框的事件.与用户按下提交按钮类似.
<TextBox Name="textBox1" Grid.Row="0" Text="Search or Type URL" Background="White" BorderBrush="{x:Null}" Margin="62,0,125,0" Foreground="#FF6E6E6E" AcceptsReturn="True" />
Run Code Online (Sandbox Code Playgroud)
上面是文本框的XAML,AcceptsReturn设置为true.
我是否添加了返回事件处理程序?
先感谢您 :)
如果您需要更多详细信息,请发表评论,我将很乐意进一步详细解释:)
你可以做的是像这样处理KeyDown事件:
private void SomeTextBox_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Enter)
{
this.Focus(); // dismiss the keyboard
// Call the submit method here
}
}
Run Code Online (Sandbox Code Playgroud)
注意: AcceptsReturn表示当在键盘上按下Return/Enter时,它将添加换行符/返回字符,而不是关闭键盘.