在 WPF 文本框中使用箭头键 (C#)
有没有办法捕获 WPF TextBox (System.Windows.Controls.Textbox
) 中的向上/向下箭头键并允许它们更改文本?我读过有关覆盖 Windows 窗体文本框 (System.Windows.Forms.TextBox
) 的 ProcessCmdKey
方法的信息,它工作得很好,但是 TextBox< /code> 远不如 WPF 灵活。是否有类似的方法可以完成此任务,而无需使用旧的 Windows 窗体 TextBox?
对于我的示例,我有一个带有数字文本掩码的文本框。我希望能够使用向上和向下箭头键来增加/减少数值。
Is there any way to catch the Up/Down arrow keys in a WPF TextBox (System.Windows.Controls.Textbox
) and allow them to alter the text? I've read about overiding the ProcessCmdKey
method for a Windows Forms TextBox (System.Windows.Forms.TextBox
), and it worked fine, but that TextBox
is not nearly as flexible as the WPF one. Is there a similar method to accomplish this without having to use the old Windows Forms TextBox?
For my example, I have a TextBox that has a numeric text-mask. I want to be able increase/decrease the numeric value by using the up and down arrow keys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向 KeyUp 和/或 KeyDown 添加事件处理程序,如果这不能满足您的需要,则应使用 PreviewKeyUp 和/或 PreviewKeyDown 。
You could add event handlers to KeyUp and/or KeyDown, if that doesn't get what you need, using PreviewKeyUp and/or PreviewKeyDown should.