I have a TextBox
bound to a property of an object which implements IDataErrorInfo
.
I set up the Validation.ErrorTemplate
of the
Tab items tend to mess up with adorners (although I don't know why, I experienced it).
I could reproduce your problem.
Solve it by wrapping the contents of the TabItem with an AdornerDecorator.
So:
<TabControl >
<TabItem Header="tabItem1" Name="tabItem1" GotFocus="tabItem1_GotFocus">
<AdornerDecorator>
<Grid>
....
</Grid>
</AdornerDecorator>
</TabItem>
...
</TabControl>
I had problem with only first (focused) tab got style and only that one persisted after changing. This is solution I ended up with (without AdornerDecorator
)
<Style TargetType="{x:Type FrameworkElement}" x:Key="ValidatingControl">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Validation.HasError" Value="True" />
<Condition Property="IsVisible" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel LastChildFill="True">
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder Name="controlWithError"/>
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}" />
</MultiTrigger>
</Style.Triggers>
Based on this article: http://techqa.info/programming/question/1369643/wpf-error-styles-only-being-rendered-properly-on-visible-tab-of-a-tab-control (No longer exists)