使用 IDataErrorInfo 并设置 Validation.HasError 样式
在 WPF 中使用 IDataErrorInfo
和 Style 我想创建表单,在验证数据时可以为最终用户提供三种不同的状态 为了使场景更清晰
1)我旁边有一个文本框我有一个图标,它为最终用户提供了什么样的输入文本框期望 - 带信息图标的初始状态
2)一旦用户输入数据,它就会验证它并决定它是否有效或不 - 大多数情况下,它会显示十字 (X) 图标,表示数据无效
3) 由于在 UpdateSourceTrigger="PropertyChanged"
上进行验证,一旦验证成功,它就会将十字图标变为绿色复选标记
即
[ ] i (tooltip- Any valid user name )
[Ga ] X (tooltip- Invalid user name. Must be 5 char long)
[Gaurav ] * (it will show only correct icon, meaning valid value)
我如何使用 IDataErrorInfo
和 Style 来实现此目的,我尝试这样做,但一旦加载我的表单,它就会使所有数据无效并第一次显示十字图标。 我想为三种状态显示不同的工具提示和不同的图标(初始信息
、无效数据
、有效数据
)
In WPF using IDataErrorInfo
and Style I want to create form where I can provide end user three different status while validating data
To make the scenario more clear
1) I have textbox next to it I have icon which provides end user what kind of input textbox expects - Initial status with information icon
2) As soon as user enter data it validates it and decides whether it is valid or not
- most of the time it will show cross (X) icon saying invalid data
3) As it is validating on UpdateSourceTrigger="PropertyChanged"
it will turn cross icon to green check mark as soon as it gets validated
i.e
[ ] i (tooltip- Any valid user name )
[Ga ] X (tooltip- Invalid user name. Must be 5 char long)
[Gaurav ] * (it will show only correct icon, meaning valid value)
How can I achieve this using IDataErrorInfo
and Style, I tried doing that but as soon as my form gets loaded it invalidates all the data and shows cross icon at the first time. I want to show different tooltip and different icon for three states (Initial info
, Invalid data
, Valid data
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IDataErrorInfo 不包含任何表示三种状态的方法。 它只知道“错误”和“无错误”。
最好的解决方案可能是通过以下方式避免使用 IDataErrorInfo:
您可能还必须为每个字段的工具提示文本创建属性。
IDataErrorInfo does not contain any means of representing three states. It only knows "error" and "no error".
The best solution may be to circumvent the use of IDataErrorInfo via the following:
You may also have to create properties for each field's tooltip text as well.
您可以在这里找到一个很好的示例 具有模型-视图-视图模型设计模式的 WPF 应用程序
you can find a great example here WPF Apps With The Model-View-ViewModel Design Pattern