Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Datagrid Cell with Validation Error Style

I am trying to change the default style of a DataGridCell (within a WPF Toolkit DataGrid) when there is a validation error. The default is a red border. How can I put my own template?

Thanks.

like image 963
joerage Avatar asked Mar 13 '10 19:03

joerage


2 Answers

Try this:

<!-- Cell Style -->
    <Style x:Key="CellErrorStyle" TargetType="{x:Type TextBlock}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip"
                        Value="{Binding RelativeSource={RelativeSource Self},
                                Path=(Validation.Errors)[0].ErrorContent}"/>
                <Setter Property="Background" Value="Yellow"/>
            </Trigger>
        </Style.Triggers>
    </Style>

And use it:

        <DataGrid.Columns>
            <DataGridTextColumn 
                ElementStyle="{StaticResource CellErrorStyle}">
            </DataGridTextColumn>
        </DataGrid.Columns>
like image 143
Jorge Navarrete Avatar answered Oct 31 '22 16:10

Jorge Navarrete


There's a nice tutorial from Diederik Krols that does exactly what you're asking for the WPF Toolkit DataGrid.

like image 45
PandaWood Avatar answered Oct 31 '22 17:10

PandaWood