0

I have a DataGrid with DataGridTextColumn on which I have a ValidationRule

<DataGridTextColumn Header="xxx" IsReadOnly="False">
   <DataGridTextColumn.Binding>
     <Binding Path="xxx" >
       <Binding.ValidationRules>
         <v:xxxValidator />
       </Binding.ValidationRules>
     </Binding>
</DataGridTextColumn.Binding>

I then have b:BindValidationResult.HasError="{Binding HasError}" on my DataGrid.

In BindValidationResult I use Validation.HasErrorProperty to listen on validationError changed.

My validation rule return return new ValidationResult(false, "");

My feeling is that I don't listen on the right property for a DataGridTextColumn because if I do the same thing with a TextBox it works like a charm.

Also, the DataGridCell get some red border when there is a error so I know that there is something happening.

I even tried this so see if the Validation.HasError would change but it doesn't trigger.

<Style.Triggers>
 <Trigger Property="Validation.HasError" Value="true">
    <Setter
        Property="ToolTip" 
        Value="{Binding RelativeSource={RelativeSource Self},
        Path=(Validation.Errors)[0].ErrorContent}"/>
    </Trigger>
</Style.Triggers>

Any help will be really appreciated on how to fix this or how to attack the problem.

Thanks

Ecnerwal
  • 362
  • 1
  • 2
  • 15
  • I'm not very familiar with `Binding.VaidationRules`, however I've always seen that Style Trigger for `Validation.HasError` used with the `IDataErrorInfo` interface on the bound data source itself. Perhaps it's not meant to be used with `Binding.ValidationRules`? `IDataErrorInfo` is the standard way of implementing validation in WPF. – Rachel Apr 09 '15 at 20:19
  • Any reason why it is the standard way? – Ecnerwal Apr 09 '15 at 20:28
  • Are you trying to add error message on tooltip? – Ayyappan Subramanian Apr 09 '15 at 20:39
  • Nah, I am trying to show a label with an error message. The label visibility would have been binded to `HasError` property. But `HasError` property never changes when using a `DataGridTextColumn`. It does change when using a TextBox alone. – Ecnerwal Apr 09 '15 at 20:41
  • can you post more code replicating your issue. – Ayyappan Subramanian Apr 09 '15 at 20:43
  • I know I'm being vague but it is hard to post more code while not crossing the line. – Ecnerwal Apr 09 '15 at 20:46
  • Is there a way to access `DataGridCell`throught `DataGridTextColumm` in xaml as in adding my `BindValidationResult.HasError="{Binding HasError}"`on it instead of my `DataGrid` – Ecnerwal Apr 09 '15 at 20:48
  • @Ecnerwal WPF's binding system uses the `IDataErrorInfo` interface when validating bindings, so most WPF developers implement their validation using that interface. I don't think I've ever seen any WPF code where someone used `Binding.ValidationRules` instead. – Rachel Apr 09 '15 at 21:03
  • This link from MSDN has a example : https://msdn.microsoft.com/en-us/library/system.windows.controls.validation.haserror(v=vs.100).aspx – Ecnerwal Apr 09 '15 at 21:05

0 Answers0