使用 ContentPresenter 进行 WPF 验证
我有一个 WPF 用户控件,需要验证某些字段。它绑定到实现 IDataErrorInfo 的类。
当我在另一个已打开的窗口中将用户控件设置为 ContentPresenter 的内容时,我可以看到正在发生验证并返回错误消息,但是,我没有得到任何验证装饰器 - 例如默认的红色轮廓。
如果我输入该字段并保留它(触发重新验证),则会出现验证装饰器。
另外,如果我在它自己的窗口中显示用户控件,它会立即显示验证装饰器。
(我正在使用 Caliburn IResults 在下面执行此操作,例如 Show.Dialog
但我怀疑这不相关)
任何人都可以提供任何建议,为什么验证装饰器不立即出现。 (我猜想我的 ContentPresenter ContentChanged 上有动画,但是,我已经删除了它,但仍然遇到问题。
谢谢, 克里斯
I have a WPF user control which needs to validate some fields. It is bound to a class implementing IDataErrorInfo.
When I set the user control as the content of my ContentPresenter in another, already open, window, I can see validation occurring, and error messages being returned, however, I don't get any validation adorner - e.g. the default red outline.
If I enter the field and leave it (triggering re-validation) the validation adorner appears.
Also, if I show the user control in it's own window it shows the validation adorner immediately.
(I'm using Caliburn IResults to do this underneath, e.g. Show.Dialog<VM>();
but I suspect this isn't related)
Can anyone offer any suggestion why the validation adorners aren't appearing immediately. (I had guessed animation on my ContentPresenter ContentChanged, however, I have removed this and still experience the problem.
thanks,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 .NET 3.5 中存在的一个已知错误。您也许可以实施解决方法,但如果可行的话,我建议升级到 .NET 4,因为这将解决您的验证问题。
This is a known bug that exists in .NET 3.5. You may be able to implement a workaround, however if it is feasible, I would recommend upgrading to .NET 4 as this will take care of your issue with validation.