Validate control manually in WPF

梦想与她 提交于 2019-12-24 17:52:35

问题


Here is the situation: I have a dataset bound to a WPF window. The dataset implements the IDataErrorInfo, so when a value is changed in the window, a validation occurs for the specific property changed. During validation, I may find out there is another control in the window I need to validate. I know only the field name in the Dataset that I need to validate, and not the actual control that binds to this field. So my questions are: 1. How can I find out what control binds to a specific field in a Dataset? 2. How do I trigger validation on that control by code?

Thanks!


回答1:


Two options as I see it:

  1. I think one way to handle this is in the setter for the property that's changed, clear the property that's no longer valid (if it is indeed not valid now).
  2. Another trick might be in the setter of the 1st property to raise a PropertyChanged event on the 2nd property, to force the view to reevaluate it.

I would prefer the 1st option, since you know changing the 1st property has a chance to invalidate the other property.



来源:https://stackoverflow.com/questions/2015600/validate-control-manually-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!