uwp - UWP 中的 TextBox 未触发 KeyDown 事件

标签 uwp textbox win-universal-app

当我按下 Enter 键时,KeyDown TextBox 的事件如果它的 AcceptsReturn 不会被触发属性设置为true。如何识别 TextBox 的 Enter 键何时被按下与 AcceptsReturn设置为 true ?

最佳答案

如果您希望完全禁用新行(如@ruffin 想要的那样),请通过隐藏代码订阅 PreviewKeyDown 事件并设置 e.Handledtrue .

    public MyControl()
    {
        InitializeComponent();

        var keyeventHandler = new KeyEventHandler(TextBox_KeyDown);
        uiText.AddHandler(PreviewKeyDownEvent, keyeventHandler, handledEventsToo: true);
    }

    private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == Windows.System.VirtualKey.Enter)
            e.Handled = true;
    }

关于uwp - UWP 中的 TextBox 未触发 KeyDown 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36938437/

相关文章:

c# - 如何在uwp中获取系统颜色列表

c# - 在应用程序设置中显示 UWP 应用程序的版本信息

c# - 如何在 C# 中处理对 Web 只读 TextBox 的单击事件

javascript - 您如何使文本字段中的文本变灰,当用户单击它时该文本会消失

xaml - 添加到 ObservableCollection 的项已成功,但仍引发异常

c# - 在通用 Windows 应用程序中从 Windows Live SDK 接收刷新 token

xaml - 检查复选框 = listviewitem 行被选中

c# - 如何使用UWP中的代码模拟Tab键按下

c# - WPF 如何动态创建文本框并在单击按钮时找到文本框?

uwp - uwphost.dll 是什么?