I have a TextBox with a validation rule that is on a tab of a TabControl. The default ErrorTemplate correctly shows (red border around TextBox) when the validation rule fails.
However if there is a switch to another tab and then back to the tab with the TextBox the ErrorTemplate hightlight is gone. If there is a change in the TextBox the validation rule is still called and returns false but the error highlight still doesn't show.
Only when the text content is changed to be valid and then again to be invalid does the highligh comeback.
I would like that if the text content is invalid that switching to another tab and back keeps the invalid highlight. Any ideas to get this behaviour most welcome.
The xaml:
<TextBox Height="35" > <TextBox.Text> <Binding Path="pan_id" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <ps:PanIdValidation /> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox>
TabItem should be defined as follows:
<TabItem Header="Foo"> <Border> <AdornerDecorator> <Grid> <TextBox Height="35" > <TextBox.Text> <Binding Path="pan_id" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <ps:PanIdValidation /> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox> </Grid> </AdornerDecorator> </Border> </TabItem>
The issue is, the Validation.Error cues are painted in the Adorner Layer. When you switch tabs, that layer is discarded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With