Domanda

I have a Datagrid I want to provide some data validation, but I need to avoid the locking mechanism that usually occurs when a cell is in an invalid state. Is there a way to bind to the IDataErrorInfo errors on a model without using the grid-locking ValidatesOnDataErrors?

To put it specifically, I want to display the tooltip and the adorner for the error without locking the grid.

Thanks!

È stato utile?

Soluzione

Turns out this can be achieved by using the validation only on the CellTemplate of a DataGridTemplateColumn.

Such as:

 <DataGridTemplateColumn Header="Destination Column">
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox IsEditable="True"
                                      IsTextSearchCaseSensitive="{Binding ElementName=caseSensitiveSearch, Path=IsChecked}"
                                      ItemsSource="{Binding AllSuggestedNames}"
                                      TextSearch.TextPath="SuggestedName"
                                      Text="{Binding ColumnMapping.DestinationColumnName, UpdateSourceTrigger=PropertyChanged}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource TextBlockValidationStyle}"
                                       Text="{Binding ColumnMapping.DestinationColumnName, 
                                                ValidatesOnDataErrors=True, 
                                                NotifyOnValidationError=True, 
                                                UpdateSourceTrigger=PropertyChanged}"
                                       Validation.ErrorTemplate="{StaticResource validationTemplate}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top