绑定时的 Silverlight 数据格式错误
当属性通过绑定(MVVM)获取其值(例如超出给定范围)时,我试图处理所有可能的错误。
通过在我想检查的控件中使用“ValidatesOnDataErrors”,这是完美的。
当我尝试检查 modelView 中的该属性是否接受给定值时,问题就出现了。
例如,当我在 DateTimePicker 控件中写入“june”时,绑定被破坏(属性是 DateTime),因此它永远无法获取其值,并且我无法像处理其余规则一样控制错误。
我应该如何尝试这个?有什么解决办法吗?
提前致谢!!
I'm trying to take care with every possible error when a property gets its value through a Binding (MVVM) like being out of a given range.
This is working perfect by using "ValidatesOnDataErrors" in the control I want to check.
The problem comes when I try to check if the given value is accepted by that property in the modelView.
For example, when I write "june" in a DateTimePicker control the binding is broken (the property is a DateTime) so it never gets its value and I can't control the errors the same way I do with the rest of rules.
How should I try this? Is there any solution?
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案非常简单!
如果您将 DateTime 属性绑定到文本框,则在 XAML 的绑定指令上设置“ValidatesOnExceptions=True”就足够了。
如果您只想自己解析它,则必须使用 ValidatesOnDataErrors=True 并创建一个验证函数来引发消息。
Solution was really simple!!
If you have a DateTime property binded to a textbox, it's enought to set "ValidatesOnExceptions=True" on Binding instruction from XAML.
If you just want to parse this by youself, you have to use ValidatesOnDataErrors=True and make a validation function to raise a message.