Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox with validation loses ErrorTemplate on tab change

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> 
like image 948
Ricibob Avatar asked Mar 28 '12 12:03

Ricibob


1 Answers

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.

like image 113
Dylan Avatar answered Sep 19 '22 08:09

Dylan