WPF 文本框预览事件相关
我有一个 WPF 文本框,并执行以下操作
- 输入文本“12345”
- 在 3 和 4 之间移动光标(使用箭头或 mouseclick)
- 输入 0(因此文本现在为“123045”)
哪个事件/事件参数可以告诉我在位置 4 处输入了 0。 我需要在预览级别知道这一点,以便我可以根据前缀和后缀数字拒绝字符 0。
I have a WPF textbox, and perform the following actions
- Enter text as "12345"
- Move cursor between 3 and 4 (using arrow or
mouseclick) - Enter 0 (so Text is now "123045")
Which event/eventargs can tell me that 0 was typed at location 4.
I need to know this at Preview level so that I can reject the character 0 based on the prefixed and suffixed digits.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 PreviewTextInput 事件中,您可以使用 TextBox 的 CaretIndex 属性来了解输入内容的位置。
In PreviewTextInput event you can use the TextBox's CaretIndex property to know the location where input is being typed.
您可以使用 PreviewTextInput 事件。 (请参阅此处了解完整的例子)
You can use the PreviewTextInput event. (see here for a complete example)