WPF 文本框预览事件相关

发布于 2024-09-05 01:50:10 字数 205 浏览 3 评论 0原文

我有一个 WPF 文本框,并执行以下操作

  1. 输入文本“12345”
  2. 在 3 和 4 之间移动光标(使用箭头或 mouseclick)
  3. 输入 0(因此文本现在为“123045”)

哪个事件/事件参数可以告诉我在位置 4 处输入了 0。 我需要在预览级别知道这一点,以便我可以根据前缀和后缀数字拒绝字符 0。

I have a WPF textbox, and perform the following actions

  1. Enter text as "12345"
  2. Move cursor between 3 and 4 (using arrow or
    mouseclick)
  3. 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄与心 2024-09-12 01:50:10

在 PreviewTextInput 事件中,您可以使用 TextBox 的 CaretIndex 属性来了解输入内容的位置。

In PreviewTextInput event you can use the TextBox's CaretIndex property to know the location where input is being typed.

丶情人眼里出诗心の 2024-09-12 01:50:10

您可以使用 PreviewTextInput 事件。 (请参阅此处了解完整的例子)

You can use the PreviewTextInput event. (see here for a complete example)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文