2
votes

I have a ObservableCollection<T> where T: INotifyDataErrorInfo.

Objects in this collection have validation errors, then I bind this collection to Silverlight 4 DataGrid, is there a way to show this validation error in DataGrid? (show red cell for invalid properties for each object). By default DataGrid show validation error only when I begin to edit row, and only for active row.

1
When I used DataGrid with the validation, I had TextBoxes as cells and everything worked fine. I'll try to implement it with your preconditions.vortexwolf

1 Answers

2
votes

I haven't succeeded with a TextBlock control, so I used a disabled TextBox You can change the template of the TextBox, I mean to remove border and to set its background really transparent.

multi row validatione

<sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items}" IsReadOnly="False" SelectionMode="Single">
    <sdk:DataGrid.Columns>
        <sdk:DataGridTextColumn Header="Title" Binding="{Binding Title}"/>
        <sdk:DataGridTemplateColumn Header="Link" Width="100">
            <sdk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Link, Mode=TwoWay}" Margin="2" 
                             IsEnabled="False" BorderThickness="0" Background="Transparent"/>
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellTemplate>
            <sdk:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Link, Mode=TwoWay}" Margin="2"/>
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellEditingTemplate>
        </sdk:DataGridTemplateColumn>
    </sdk:DataGrid.Columns>
</sdk:DataGrid>