Reputation: 22445
first my validation template
<ControlTemplate x:Key="ValidationTemplate" >
<Grid>
<AdornedElementPlaceholder Name="MyAdornedElement" />
<Path x:Name="path" Margin="-2,-2,0,0" Data="M 0,10 L 10,0 L 0,0 Z" Fill="{StaticResource BrushError}" StrokeThickness="2" Stroke="White"
Visibility="{Binding ElementName=MyAdornedElement,Path=AdornedElement.Visibility}"
ToolTip="{Binding ElementName=MyAdornedElement,Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}"/>
</Grid>
</ControlTemplate>
and my textbox style
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationTemplate}"/>
<Setter Property="UndoLimit" Value="0"/>
<Style.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderThickness" Value="{StaticResource IsFocusBorderThickness}"/>
<Setter Property="BorderBrush" Value="{StaticResource IsFocusBorderBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource IsDisabledForegroundBrush}"/>
</Trigger>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding Path=(Validation.Errors).CurrentItem.ErrorContent, RelativeSource={x:Static RelativeSource.Self}}"/>
</Trigger>
</Style.Triggers>
</Style>
and now the mysterius behavior
i have a tabcontrol with 2 tabpages, each of the pages contains textboxes. if i open my view and move from first to second tabpage a back and then push the validate button - all is fine, my validation template is shown for all textboxes on both tabpages.
BUT when i just open the view and dont navigate to tabpage 2 - then push the validate button - just the textboxes on tabpage 1 have the validation template shown. even more when i hit the button again on the validation template its not show on tabpage 2.
Any hints what i'm missing?
EDIT: if i use snoop and walk on the snoop treeview to my textbox on tabpage 2, then the validation Template Adorner is visible as far as i click on the TextBox in the Snoop Treeview...
Upvotes: 1
Views: 287
Reputation: 22445
if i add the following to my textbox style it works.
<Trigger Property="IsVisible" Value="false">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
</Trigger>
<Trigger Property="IsVisible" Value="true">
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationTemplate}"/>
</Trigger>
Upvotes: 1