Need Validate All Properties in Class with IDataErrorInfo Implemented
I have a WPF window that has a datacontext of my class 'Item'. When a user types in a TextBox the validation triggers with no issues. I need to validate this TextBox and every other Property that is set in this bound class when the user clicks 'Save'.
I don't believe UpdateSourceTrigger is what I'm looking for, although I have it set to PropertyChanged for when the user does actually do data entry on the field.
I would rather not set all my properties to the correspondi开发者_运维问答ng UI control on the Save click to force the update on the property but I could.
Thanks!
Data error validation only gets executed when binding pushes new property values out to the data source. If you want to execute that validation under any other circumstances, you have to write code to do it.
If your UI properties are bound to the item's properties, then the validation already should have run for each of them when the Save
button is clicked. So why do you need to run it again?
One common issue is where you've set your bindings to update on LostFocus
, but the object that the user clicks on to save the item isn't focusable. In this case, the last property updated in the UI isn't updated in the data source when the item is saved, since its control hasn't lost focus and its binding hasn't fired. Is that your problem?
精彩评论