Hi guys,
I have an object which implements the IDataErrorInfo and IValidatableObject interfaces. When the indexer for the property 'Quantity' of this object gets called it calls a validation method that fetches some value from the database to check it against the entered value. I have noticed that when I edit the 'Quantity' property, the indexer is being called multiple times because of calls to the DataGrid.Cell.UpdateContentBindingTarget method. Specifically, when I enter a value that
makes the validation method succeed, the indexer is called 3 times but when I enter a value that makes the validation method fail, the indexer is being called 13 times.
Below, is the simplified xaml and the stack trace of these calls. Why is this happening and is there a way to prevent all these data binding updates?
this sequence is called 2 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.EndEdit()
DataGrid.Row.EndEditCore()
DataGrid.DataRow.EndEditCore()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
and then this sequence is called 1 time for a total of 3 calls to my object's indexer.
DataGrid.Cell.UpdateContentBindingTarget()
DataGrid.Row.UpdateCellsContentBindingTarget()
DataGrid.Row.TerminateEditionFromEndEdit()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
--- StackTrace when the validation method fails:
this sequence is called 2 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.EndEdit()
DataGrid.Row.EndEditCore()
DataGrid.DataRow.EndEditCore()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
then this sequence is called 6 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.CascadeValidation()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Row.EndEditCore()
DataGrid.DataRow.EndEditCore()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
then this sequence is called 4 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.CascadeValidation()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.ContentBinding_TargetUpdated()
and finally this sequence is called 1 times for a total of 13 calls to my object's indexer.
DataGrid.Cell.UpdateContentBindingTarget()
DataGrid.Row.UpdateCellsContentBindingTarget()
DataGrid.Row.TerminateEditionFromEndEdit()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
I have an object which implements the IDataErrorInfo and IValidatableObject interfaces. When the indexer for the property 'Quantity' of this object gets called it calls a validation method that fetches some value from the database to check it against the entered value. I have noticed that when I edit the 'Quantity' property, the indexer is being called multiple times because of calls to the DataGrid.Cell.UpdateContentBindingTarget method. Specifically, when I enter a value that
makes the validation method succeed, the indexer is called 3 times but when I enter a value that makes the validation method fail, the indexer is being called 13 times.
Below, is the simplified xaml and the stack trace of these calls. Why is this happening and is there a way to prevent all these data binding updates?
<xcdg:DataGridControl AutoCreateColumns="False" IsDeleteCommandEnabled="False" IsRefreshCommandEnabled="False" ItemScrollingBehavior="Immediate" ItemsSource="{Binding Path=OrderDetails}">
<xcdg:Column FieldName="Quantity" CellEditorDisplayConditions="CellIsCurrent" CellHorizontalContentAlignment="Right" Title="Quantity">
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=., StringFormat={}{0:N0}, ValidatesOnDataErrors=True}" />
</DataTemplate>
</xcdg:Column.CellContentTemplate>
<xcdg:Column.CellErrorStyle>
<Style TargetType="{x:Type xcdg:Cell}" >
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="1" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
</xcdg:Column.CellErrorStyle>
<xcdg:Column.CellEditor>
<xcdg:CellEditor>
<xcdg:CellEditor.EditTemplate>
<DataTemplate>
<xceed:IntegerUpDown Value="{xcdg:CellEditorBinding}" Minimum="0" />
</DataTemplate>
</xcdg:CellEditor.EditTemplate>
</xcdg:CellEditor>
</xcdg:Column.CellEditor>
</xcdg:Column>
</xcdg:DataGridControl>
-- StackTrace when the validation method succeeds:this sequence is called 2 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.EndEdit()
DataGrid.Row.EndEditCore()
DataGrid.DataRow.EndEditCore()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
and then this sequence is called 1 time for a total of 3 calls to my object's indexer.
DataGrid.Cell.UpdateContentBindingTarget()
DataGrid.Row.UpdateCellsContentBindingTarget()
DataGrid.Row.TerminateEditionFromEndEdit()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
--- StackTrace when the validation method fails:
this sequence is called 2 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.EndEdit()
DataGrid.Row.EndEditCore()
DataGrid.DataRow.EndEditCore()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
then this sequence is called 6 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.CascadeValidation()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Row.EndEditCore()
DataGrid.DataRow.EndEditCore()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()
then this sequence is called 4 times
DataGrid.Cell.UpdateContentBindingSource()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.CascadeValidation()
DataGrid.Cell.ValidateAndSetAllErrors()
DataGrid.Cell.ContentBinding_TargetUpdated()
and finally this sequence is called 1 times for a total of 13 calls to my object's indexer.
DataGrid.Cell.UpdateContentBindingTarget()
DataGrid.Row.UpdateCellsContentBindingTarget()
DataGrid.Row.TerminateEditionFromEndEdit()
DataGrid.Row.EndEdit()
DataGrid.DataGridControl.OnPreviewMouseDown()