0

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

H.B.
  • 166,899
  • 29
  • 327
  • 400
Tekito
  • 840
  • 8
  • 24
  • 1. Use `Path=(Validation.Errors).CurrentItem.ErrorContent` 2. Any output into console? – jamesSampica Aug 16 '13 at 21:22
  • Console is blank. `CurrentItem` doesn't appear to change anything. Considering that the `Background` setter is also not firing, I'm guessing the problem is deeper. I'm wondering if `TargetType` should not be a combobox, but targeting TextBlock throws an error. – Tekito Aug 16 '13 at 21:30
  • You could try `DataGridTemplateColumn` and set the style on the a combobox inside. I didn't mean for `CurrentItem` to be a fix, it's just a better way of getting the error item. – jamesSampica Aug 16 '13 at 22:00
  • Ah thanks then. Yeah I probably should give `TemplateColumn` a go. Crossed fingers that doesn't open up another can of worms. – Tekito Aug 16 '13 at 22:10
  • I know that its really too late but it works for me when i apply the style on property : EditingElementStyle – Kevin VDF Nov 22 '17 at 15:38

0 Answers0