2011-07-29 13 views
3

私は現在、私のDataGridの行の検証を使用しています。私はそれが有効でないときに行の外観を変更しようとしています。これまで視覚的にエラーを報告するという私のコード:wpf DataGrid.RowValidationErrorTemplate - ヘッダー行の代わりに行の外観を実際に変更する方法は?

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

これは私のヘッダー行にのみ影響するようです。行の外観を変更するために、このRowValidationErrorTemplateを処理できる方法はありますか?私は行の背景全体を赤色にするか、それとも何かをしたいと思います。

アイデア? この特定の問題に対してさらにコードを提供する必要があるかどうか教えてください。 ありがとうございます!

答えて

5

DataGridRow型のスタイルを更新し、行に対する検証フラグに基づいてエラーバックグラウンドを設定できます。

このような何か...

<DataGrid.Resources> 
     <Style TargetType="{x:Type DataGridRow}" 
      BasedOn="{StaticResource (x:Type DataGridRow)}"> <!--BasedOn is optional--> 
      <Style.Triggers> 
       <Trigger Property="Validation.HasError" Value="True"> 
        <Setter Property="Background" Value="Red"/>   
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </DataGrid.Resources> 

は、このことができますなら、私に教えてください。

関連する問題