I'm having trouble concerning validation in DataGrid. I'm using IDataErrorInfo validation in model classes.
The problem is in editable DataGrid with separate CellTemplate and CellEditingTemplate (Note is a not-null property - validation returns Error if null or empty):
<!-- some other validated columns -->
<DataGridTemplateColumn Header="Note">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Name="textBoxNote" Text="{Binding Note, ValidatesOnDataErrors=True}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Note}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
On Save button, I check MyObject.Error validation property and if not null I show a MessageBox. The problem is that when changing the first column (not the Note one) to a valid value and then clicking Save button, the .Error property is null - this is expected (although unwanted) behavior because the binding with ValidatesOnDataError on Note property never happened (the TextBox control never even existed!). But if I set the ValidatesOnDataErrors to true on TextBlock then I get the undesired validation on every object shown in a DataGrid (say from a database) that I'm not concerned about; validation can also take a lot of time in this case...
What would be the proper way to handle this issue? I would like to keep validation in model classes (the object should know about whether it's valid or not). Is there any way to force validation of a row-bound object in codebehind (Save button event)? Or should I somehow initialize .Error on object construction? Any other ideas?
EDIT: how could I put the whole row (all cells) into edit mode (CellEditingTemplate)? Then, all of the controls would be loaded and databound, this also means validated...
Thanks to all, DB