【问题标题】:Close keyboard on tapping on Enter点击 Enter 时关闭键盘
【发布时间】:2014-06-03 10:11:22
【问题描述】:

我使用适用于 Windows Phone 8 的工具包,并且有一个带有 AutoCompleteBox 的页面。

现在,如果用户在未选择当前项目的情况下向 AutoCompleteBox 写入内容(用户键入不同的文本)并使用“Return”提交文本,我想关闭键盘。

如何做到这一点?

【问题讨论】:

    标签: c# windows-phone-8 silverlight-toolkit


    【解决方案1】:

    你可以这样做,

    <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

    【讨论】:

      【解决方案2】:

      您可以使用 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();
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-02-09
        • 1970-01-01
        • 2020-05-22
        • 1970-01-01
        • 2021-03-24
        • 2011-05-10
        • 1970-01-01
        • 2012-03-11
        • 1970-01-01
        相关资源
        最近更新 更多