检测TextBox是否包含无效数据 [英] Detecting if a TextBox has invalid data

查看:87
本文介绍了检测TextBox是否包含无效数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我在屏幕上有一些TextBox和一个执行命令的按钮。每个TextBox都绑定到类型不同的特定属性。例如,一个TextBox绑定到Double属性。 WPF的美妙之处在于,当
不是Double的值输入TextBox时,TextBox以红色标出。太棒了!


但是,有没有办法检测其中一个TextBox何时显示非法值?


最终,我想制作根据具有"非法值"的一个或多个TextBox的事实启用或禁用按钮的命令。概述他们。我不知道是否有一个内置的方法来使用WPF。有时
我只是为了实现某些事情而花费很长时间来实现WPF已经内置的能力。


任何想法?


谢谢!

解决方案

WPF有一个可以使用的验证机制。 以下链接显示了:


https:// stackoverflow的.com /问题/ 19539492 /执行验证换WPF的文本框


Basically, I have some TextBoxes on the screen and a button that executes a command. Each TextBox is bound to a particular property that varies in type. For example, one TextBox is bound to a Double property. The beauty with WPF is that when a value that is not a Double is entered into the TextBox the TextBox is outlined in red. Great!

However, is there a way to detect when one of those TextBoxes is showing an illegal value?

Ultimately, I want to make the command that's bound to the button enabled or disabled based on the fact of one or more TextBoxes having the "illegal value" outline on them. I didn't know if there was a built-in way to do this with WPF. Sometimes I take the long route in doing something only to realize WPF already has the ability built-in.

Any ideas?

Thanks!

解决方案

WPF has a Validation mechanism that can be used.  The following link shows how:

https://stackoverflow.com/questions/19539492/implement-validation-for-wpf-textboxes


这篇关于检测TextBox是否包含无效数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆