Редагувати

Поділитися через


DataGrid.RowValidationErrorTemplate Property

Definition

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

public:
 property System::Windows::Controls::ControlTemplate ^ RowValidationErrorTemplate { System::Windows::Controls::ControlTemplate ^ get(); void set(System::Windows::Controls::ControlTemplate ^ value); };
public System.Windows.Controls.ControlTemplate RowValidationErrorTemplate { get; set; }
member this.RowValidationErrorTemplate : System.Windows.Controls.ControlTemplate with get, set
Public Property RowValidationErrorTemplate As ControlTemplate

Property Value

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.

Examples

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.

<DataGrid.RowValidationErrorTemplate>
  <ControlTemplate>
    <Grid Margin="0,-2,0,-2"
      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>

Remarks

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.

Applies to

See also