I'm new to wpf, I need to use a WPF DataGrid which has its ItemSource set to an ObservableCollection of type Model, where Model implements the IDataErrorInfo class. The problem I am facing is that if the Model returns a validation string for any property, then the user is unable to exit the edit mode for the cell, I tried rollback & I even tried CancelEdit, but I can't exit the edit mode. I searched on msdn and I found out the its one of DataGrid's property but I need to do the same because of some application requirements.
My Model Class:
public class Model: IDataErrorInfo
{
public int PropertyName{ get; set; }
// other properties & methods removed for clarity
public string this[columnName]
{
get
{
if (PropertyName< 0)
return "Error Message";
else
return string.Empty;
}
}
}
Now if 'PropertyName' is less than 0, the user cannot exit the edit mode of the specific cell.
This link on msdn says in 'Remarks' that
The DataGrid will not exit cell editing mode until the validation error is resolved.
Is there any workaround to exit the cell edit mode even if the Validation has returned an error message? I can't help with the code architecture because I am stuck with DataGrid as well as the 'Model' class. Any help would be appreciated, Thanks a lot in advance.
this[columnName]
(in my Model inherited fromIDataErrorInfo
), so the list is getting filled all right. By Validation constraints I basically mean things like "Property should be between 10 and 20". Now lets suppose the user adds a new row, Validations occur on 4 properties so the list will be filled (it is filled, I can give the code if required). – Rachit Magon