Silverlight 4 中的过滤膏
我有 TextBox
,它只允许插入数值(过滤),但是当我粘贴复制的文本时,它允许任何类型的符号。如何在粘贴之前阻止或过滤文本?
I have TextBox
which allow insert only numeric values (filtering), But when I paste copied text it's allow any kind of symbol. How can I prevent or filter text before pasting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在任何手动输入之前备份文本,然后当提供的输入无效时恢复以前的文本,如下所示:
我不建议 尝试捕获控制键或任何东西,因为当你在 Mac 或 Linux 上时,你就完蛋了。
调整我的样本并将其倒入新的文本框控件中以使其更干净,但您明白了。
You could backup your text before any manual input and then when the input provided isn't valid restore the previous text like so:
I wouldn't recommend trying to capture the control keys or anything because when you're on a mac or on linux then you're screwed.
Adjust my sample and pour it inside a new textbox control to make it cleaner but you get the idea.
您可以使用 Clipboard.GetText() 获取插入到文本框中的文本,但这会弹出一条消息,并且用户必须授予应用程序访问剪贴板的权限。
如果对你来说没问题那么我会用这个。
You could use Clipboard.GetText() to get the text that is inserted into the textbox, but this will pop up a message, and the user must give the application access to the Clipboard.
If its no problem for you then i would use this.