2

I have a DataGrid, which is showing some stuff. Each of the cells has a validation on it, using the IDataErrorInfo interface. When the user puts invalid data into the cell, the validation fails and the user is alerted, both by the cell's background turning red, and the error icon appearing to the left of the row. When the user corrects the data, the cell's background goes back to normal, but the error icon doesn't clear. This happens even if I don't define the RowValidationErrorTemplate.

       <DataGrid AutoGenerateColumns="False" Height="Auto" HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Top" Width="Auto" 
                  ItemsSource="{Binding Path=Records}" ColumnWidth="Auto" CanUserReorderColumns="False" 
                  CanUserResizeColumns="False" SelectionUnit="Cell" CanUserAddRows="True">

        <DataGrid.RowValidationRules>
            <vm:TimeoutRecordRowValidation ValidationStep="UpdatedValue"/>
        </DataGrid.RowValidationRules>

        <DataGrid.RowValidationErrorTemplate>
            <ControlTemplate>
                <Grid ToolTip="{Binding RelativeSource={RelativeSource
                    FindAncestor, AncestorType={x:Type DataGridRow}},
                    Path=(Validation.Errors)[0].ErrorContent}">
                    <Ellipse StrokeThickness="0" Fill="Red"
                             Width="{TemplateBinding FontSize}"
                             Height="{TemplateBinding FontSize}" />
                        <TextBlock Text="!" FontSize="{TemplateBinding FontSize}"
                               FontWeight="Bold" Foreground="White"
                               HorizontalAlignment="Center" />
                </Grid>
            </ControlTemplate>
        </DataGrid.RowValidationErrorTemplate>

        <DataGrid.Resources>
            <Style x:Key="DefaultColumnHeaderStyle" TargetType="DataGridColumnHeader">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Column.(ToolTipService.ToolTip)}" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataGrid.Resources>

        <DataGrid.Columns>
            <DataGridTextColumn Header="LabelFamilyID&#x0a;XXX"
                                    Binding="{Binding Path=LabelFamilyID, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                                    ElementStyle="{StaticResource ErrorStyle}">
            </DataGridTextColumn>
            <DataGridTextColumn Header="ModelCapacityString&#x0a;WD????????"
                                    Binding="{Binding Path=ModelCapacityString, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                                    ElementStyle="{StaticResource ErrorStyle}">
            </DataGridTextColumn>
            <DataGridTextColumn Header="Timeout Value&#x0a;99:99:99"
                                    Binding="{Binding Path=TimeoutValue, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                                    ElementStyle="{StaticResource ErrorStyle}">
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

I have trimmed some of the XAML that is unrelated, like the HeaderStyle definitions, for brevity.

s73v3r
  • 1,751
  • 2
  • 22
  • 48

3 Answers3

0

I added the following directly under DataGrid. It removes the exclamation mark. It is not a "fix" but it does not have unexpected results either

<DataGrid.RowValidationErrorTemplate>
    <ControlTemplate>
        <Grid Margin="0,-12,0,-12" ToolTip="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=(Validation.Errors)[0].ErrorContent}">
        </Grid>
    </ControlTemplate>
</DataGrid.RowValidationErrorTemplate>
Athafoud
  • 2,898
  • 3
  • 40
  • 58
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
-1

this remove the exclamation mark too:

<Setter Property="ValidationErrorTemplate" Value="{x:Null}"/>

I hope MS correct it in the final version of VS2013 update 5

BDisp
  • 99
  • 6
-1

I'm not sure what it was, but in each of the DataGridTextColumns, removing the

Mode=TwoWay

from each of the Binding elements did the trick.

s73v3r
  • 1,751
  • 2
  • 22
  • 48
  • Do you remember if this was your final solution? I don't have mode=twoway on mine, and the red exclamation won't go away after correcting an error. – Jake Gaston Oct 10 '14 at 15:23