(VS 2010) I have a DataGridComboBobxColum
in my WPF datagrid. I'm trying to use a validation rule that is evaluated upon UpdatedValue
:
<DataGridComboBoxColumn Header="Model" x:Name="ModelCBColumn"
ElementStyle="{StaticResource cbErrorStyle}" >
<DataGridComboBoxColumn.SelectedItemBinding>
<Binding Path="Model" Mode="TwoWay" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:ModelValidationRule ValidationStep="UpdatedValue" />
</Binding.ValidationRules>
</Binding>
</DataGridComboBoxColumn.SelectedItemBinding>
The ElementStyle
is then supposed to change the cell background and display a tooltip for validation errors:
<Style x:Key="cbErrorStyle" TargetType="{x:Type ComboBox}">
<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>
But my ElementStyle
never gets applied. Instead, for validation errors there is the default red border around the cell and a !
icon in the row header. No tooltip or yellow background. Worse, when the cell is corrected, the red border will disappear but the !
remains. There are no row validation rules. I have done a very similar approach for TextBoxColumns
with no problems, so don't know what the issue is here.