Why has this glaring bug not been fixed in WPF by now! It's driving me crazy.
I know this question has been asked numerous times, but no solution I've come across works for me, and I'm using the "simplest" of bindings:
<mui:DataGridTextColumn x:Name="colDeviceName"
Header="Name"
Binding="{Binding Name,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True}"
Width="Auto"
IsReadOnly="false"
EditingElementStyle="{StaticResource errorStyle255}">
</mui:DataGridTextColumn>
I simply do not want a blank value entered. I've implemented IDataErrorInfo
and INotifyPropertyChanged
in the bound class and indeed, if a blank value is entered, an appropriate error Tooltip
is displayed and you must correct this before you can commit the current row.
But when you do correct the error, you ARE allowed to leave the row! Instead, the error exclamation mark is still there!
This is an issue because my save code will not allow the data to be committed if the Grid
has any errors:
public static bool DataGridHasErrors(DataGrid grid)
{
bool result = false;
for (int i = 0; i < grid.Items.Count; i++)
{
DataGridRow row = GetRow(grid, i);
if (row != null && Validation.GetHasError(row))
{
result = true;
break;
}
}
return result;
}
I've tried various permutations of the binding mode and UpdateSourceTrigger
, but none of them is working satisfactory for my needs (usually the bound object is not updated etc).
I mean, why has this blatant bug not been addressed?
All/any suggestions welcome
Thanks
I've seen this post SO Post WPF DataGrid and Validation Errors not clearing and it suggests not using TwoWay
binding mode - but doesn't this defeat the purpose? How would I update and validate the bound class if the UI was not updating it?