We are using XamMaskedEditor in the XamDataGrid and when we use a required field mask like '###-##-####', and blank the value out using the backspace, when it gets to a blank value, we get a DataError in the XamDataGrid : Cannot set column '<COLUMN>' to be null. Please use DBNull instead.
We can catch the error in the DataError as such :
if (e.Message.Contains("Please use DBNull instead"))
{
e.Cell.Value =
DBNull.Value;
e.Cancel =
true;
}
But we feel that is a hack. Is there a more proper way to tell the XamMaskEditor to coerce a blank string to DBNull and not Null? When we bind this XamMaskEditor to the same dataset not in a XamDataGrid, we don't experience the error, so we feel the issue might be more with the binding between the MaskedEditor and the Grid.
I have a similar situation with a numeric mask:
Value="{}{double:2.2}"
Only in my case the DataError is "Unable to set cell value". I can use the same hack to set the cell value to "0".
Anyone else have a more proper way to work with the XamMaskEditor?
Michael Frank
So for what it's worth. I ended up creating a "NullToZeroConverter" (IValueConverter) and adding it as a resource to my xaml.
<Converters:NullToZeroConverter x:Key="nullToZeroConverter"/>