SL 4:文本框没有按下 Ctrl-V?

发布于 2024-12-26 06:38:31 字数 1413 浏览 3 评论 0原文

我们有一个 TextBox 控件作为更大的 UserControl 的一部分。
UserControl 有一个绑定到 KeyDown 事件的 MVVMLight RelayCommand:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="KeyDown">
        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding KeyDownCommand}"  PassEventArgsToCommand="True"/>
    </i:EventTrigger> </i:Interaction.Trigger>

当 TextBox 获得焦点时,可以看到 Ctrl 键的 KeyDown 事件,但看不到 Ctrl+ V
我在代码隐藏中添加了 TextBox 的 KeyDown 的处理程序:

                     KeyDown="textBox_KeyDown"

        private void textBox_KeyDown(object sender, KeyEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(string.Format("textBox_KeyDown Key: {0}  Modifier: {1}", e.Key, Keyboard.Modifiers));
        e.Handled = false;
    }

类似的结果 - 处理 Ctrl 键的 KeyDown 事件,但 Ctrl+ V 没有出现。
消息通过其他处理程序冒泡,但从未标记为已处理。
关于为什么文本框没有获得 Ctrl+V 有什么想法吗?
感谢您的任何见解。

更新:哦,看在皮特的份上...我在代码隐藏中添加了一个 KeyUp 处理程序,并且 Ctrl+V 出现在那里。但是,当不同的控件(例如,包含 ScrollViewer)是 KeyDown 的源时,Ctrl+V 会出现在 KeyDown 处理程序中。
更新第二个:在一个新的稀疏项目中,我验证了 Ctrl+V 不会调用 TextBox.KeyDown 处理程序,而TextBox.KeyUp 被 Ctrl+V 调用。是否可以将 Ctrl+V 事件“传递”到另一个文本框?

We have a TextBox control as part of a larger UserControl.
The UserControl has an MVVMLight RelayCommand bound to the KeyDown event:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="KeyDown">
        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding KeyDownCommand}"  PassEventArgsToCommand="True"/>
    </i:EventTrigger> </i:Interaction.Trigger>

When the TextBox has focus, the KeyDown events for the Ctrl key are seen, but not the Ctrl+V.
I added a handler for the KeyDown for the TextBox in code-behind:

                     KeyDown="textBox_KeyDown"

        private void textBox_KeyDown(object sender, KeyEventArgs e)
    {
        System.Diagnostics.Debug.WriteLine(string.Format("textBox_KeyDown Key: {0}  Modifier: {1}", e.Key, Keyboard.Modifiers));
        e.Handled = false;
    }

Similar result -- a KeyDown event for the Ctrl key is handled, but the Ctrl+V doesn't show up.
The message bubbles up through other handlers, but is never marked handled.
Any ideas on why the TextBox isn't getting the Ctrl+V?
Thanks for any insights.

Update: Oh, for Pete's sake... I added a KeyUp handler in the code-behind, and the Ctrl+V appears there. However, the Ctrl+V appears in a KeyDown handler when a different control (a containing ScrollViewer, for example) is the source of the KeyDown.
Update the Second: With a new, sparse project, I verified that the TextBox.KeyDown handler does NOT get called for Ctrl+V, while TextBox.KeyUp gets called for Ctrl+V. Is it possible to "pass along" the Ctrl+V event to another TextBox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文