Reputation: 11
I have binding validation in a WPF application, but now because of some rules some textboxes get disabled, and the validation shows the same way. Is there a way to disable the validation when the controls are disabled and turn them back on when enabled?
Upvotes: 0
Views: 882
Reputation: 6745
You can remove the validation template when the controls are disabled.
Note, this doesn't prevent the validation rules from running, this will just remove the validation template.
If you're using a ValidationRule, you can obtain a reference to the textbox, and check to see if the textbox is enabled.
Place the following in your textbox style:
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<Border BorderBrush="Gray"
BorderThickness="0">
<AdornedElementPlaceholder />
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
Upvotes: 1