WPF 验证 - ValidatesOnTargetUpdated
我在 WPF 应用程序中有许多文本框,我在其中设置了一些验证。
加载时,应用程序会反序列化 WPF 窗口控件所绑定的类。
我有一个 ValidationRule(例如)测试文件是否存在。如果我没有设置 ValidatesOnTargetUpdated,则当我更改(绑定)文本属性时,相应的 TextBox 会进行验证,并且我会看到出现(默认)红色边框和工具提示 ({BindingrelativeSource={x:StaticRelativeSource.Self} , Path=(Validation.Errors).CurrentItem.ErrorContent}
) 显示错误消息。
我希望控件在绑定时验证,而不是在属性更改时验证,因此我已将 ValidatesOnTargetUpdated 设置为 true,并且可以在调试时看到验证规则触发。
我的问题是,尽管 ValidationRule 触发,但当 ValidatesOnTargetUpdated="True" 时,(默认)ValidationTemplate 会被忽略。
我可以看到工具提示 - 它显示正确的错误消息,但边框不显示为红色;这似乎被忽略了。
有什么想法为什么会发生这种情况吗?
I have a number of textboxes in a WPF app on which I have set up some validation.
On load the app deserialises a class onto which the WPF window's controls are bound.
I have a ValidationRule that (for example) tests that a file exists. If I don't set ValidatesOnTargetUpdated then the corresponding TextBox validates when I change the (bound) Text Property and I see the (default) red border appear and a Tooltip ({Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}
) displaying the error message.
I want the controls to validate on binding rather than on propertychanged so I have set the ValidatesOnTargetUpdated to true and can see the validationRule firing when debugging.
My problem is that the (default) ValidationTemplate is ignored when ValidatesOnTargetUpdated="True"
despite the ValidationRule firing.
I can see the Tooltip - it appears with the correct error message but the border doesn't show as Red; this seems to be ignored.
Any ideas why this would be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想阅读此论坛帖子< /a>.我相信与您的情况相关的部分是:
编辑:
可以在此处找到更永久的链接。
You may want to read this forum post. I believe the part that pertains to your situation is:
EDIT:
A more permanent link can be found here.