【发布时间】:2014-06-03 10:11:22
【问题描述】:
我使用适用于 Windows Phone 8 的工具包,并且有一个带有 AutoCompleteBox 的页面。
现在,如果用户在未选择当前项目的情况下向 AutoCompleteBox 写入内容(用户键入不同的文本)并使用“Return”提交文本,我想关闭键盘。
如何做到这一点?
【问题讨论】:
标签: c# windows-phone-8 silverlight-toolkit
我使用适用于 Windows Phone 8 的工具包,并且有一个带有 AutoCompleteBox 的页面。
现在,如果用户在未选择当前项目的情况下向 AutoCompleteBox 写入内容(用户键入不同的文本)并使用“Return”提交文本,我想关闭键盘。
如何做到这一点?
【问题讨论】:
标签: c# windows-phone-8 silverlight-toolkit
你可以这样做,
<AutoCompleteBox Name="Input" KeyUp="Input_KeyUp" FontSize="40">
<AutoCompleteBox .InputScope>
<InputScope>
<InputScopeName />
</InputScope>
</AutoCompleteBox .InputScope>
</AutoCompleteBox >
在活动中,
private void Input_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
this.Focus();
}
}
在这里阅读整篇文章:Dismiss the SIP (keyboard) in WP8
【讨论】:
您可以使用 KeyUp 事件处理程序关闭键盘,然后选择当前页面的 Focus():
void textBox_KeyUp(object sender, KeyEventArgs e)
{
// if the enter key is pressed
if (e.Key == Key.Enter)
{
// focus the page in order to remove focus from the text box
// and hide the soft keyboard
this.Focus();
}
}
【讨论】: