DataGrid.RowValidationErrorTemplate Property

.NET Framework (current version)

Gets or sets the template that is used to visually indicate an error in row validation.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

member RowValidationErrorTemplate : ControlTemplate with get, set

Property Value

Type: System.Windows.Controls.ControlTemplate

The template that is used to visually indicate an error in row validation. The registered default is null. For more information about what can influence the value, see DependencyProperty.

The DataGrid control enables you to perform validation at both the cell and row level. With cell-level validation, you validate individual properties of a bound data object when a user updates a value. With row-level validation, you validate entire data objects when a user commits changes to a row. You can provide customized visual feedback for row-level validation errors by specifying a ControlTemplate that defines the appearance of the error indicator. Set the RowValidationErrorTemplate property to null to use the default error indicator.

The following example replaces the default row validation feedback with a more visible indicator. When a user enters an invalid value, a red circle with a white exclamation mark appears in the row header. The associated error message is displayed in a ToolTip. This code example is part of a larger example provided for the How to: Implement Validation with the DataGrid Control topic.

    <Grid Margin="0,-2,0,-2"
      ToolTip="{Binding RelativeSource={RelativeSource
      FindAncestor, AncestorType={x:Type DataGridRow}},
      <Ellipse StrokeThickness="0" Fill="Red" 
        Width="{TemplateBinding FontSize}" 
        Height="{TemplateBinding FontSize}" />
      <TextBlock Text="!" FontSize="{TemplateBinding FontSize}" 
        FontWeight="Bold" Foreground="White" 
        HorizontalAlignment="Center"  />

.NET Framework
Available since 4.0
Return to top