Share via


DataGrid.RowValidationErrorTemplate 屬性

定義

取得或設定用來以視覺效果指示列驗證錯誤的範本。

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

屬性值

ControlTemplate

用來在資料列驗證中,以視覺方式表示錯誤的範本。 已註冊的預設值是 null。 如需哪些因素會影響值的詳細資訊,請參閱 DependencyProperty

範例

下列範例會將預設資料列驗證意見反應取代為較可見的指標。 當使用者輸入不正確值時,資料列標頭中會出現具有白色驚嘆號的紅色圓圈。 相關聯的錯誤訊息會顯示在工具提示中。 此程式碼範例是 如何:使用 DataGrid 控制項 實作驗證主題所提供的較大範例的一部分。

<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>

備註

控制項 DataGrid 可讓您在儲存格和資料列層級執行驗證。 透過資料格層級驗證,您可以在使用者更新值時驗證系結資料物件的個別屬性。 使用資料列層級驗證時,您會在使用者認可資料列的變更時驗證整個資料物件。 您可以藉由指定定義錯誤指標外觀的 , ControlTemplate 提供資料列層級驗證錯誤的自訂視覺化回饋。 將 RowValidationErrorTemplate 屬性設定為 null ,以使用預設的錯誤指標。

適用於

另請參閱