绑定时的 Silverlight 数据格式错误

发布于 2024-11-14 08:50:53 字数 286 浏览 9 评论 0原文

当属性通过绑定(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 技术交流群。

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

发布评论

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

评论(1

说好的呢 2024-11-21 08:50:53

解决方案非常简单!

如果您将 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.

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