【问题标题】:Windows phone 8 Textbox accept return as submit buttonWindows phone 8 文本框接受返回作为提交按钮
【发布时间】:2014-07-20 12:07:09
【问题描述】:

在我的应用程序中,我有一个文本框,当用户按下键盘上的返回按钮时,它应该为文本框提供一个事件。类似于用户按下提交按钮。

<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" />

上面是文本框的 XAML,AcceptsReturn 设置为 true。

我要添加返回事件处理程序吗?

提前谢谢你:)

如果您需要更多详细信息,请发表评论,我很乐意进一步详细解释:)

【问题讨论】:

    标签: c# xaml windows-phone-8 textbox event-handling


    【解决方案1】:

    您可以像这样处理 KeyDown 事件:

    private void SomeTextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.Key == Key.Enter)
        {
             this.Focus(); // dismiss the keyboard
             // Call the submit method here
        }
    }
    

    注意: AcceptsReturn 表示当在键盘上按下 Return/Enter 时,它会添加一个换行符/Return 字符,而不是关闭键盘。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-08
      • 2013-06-10
      • 1970-01-01
      相关资源
      最近更新 更多