Reputation: 5002
I add theme for application.
I set style for textbox, and set Validation.ErrorTemplate for it.
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource TextBoxValidationToolTipTemplate}"
in validation template.
<ControlTemplate x:Key="TextBoxValidationToolTipTemplate">
<Grid x:Name="Root" Margin="5,0" Opacity="0" RenderTransformOrigin="0,0">
<Grid.RenderTransform>
<TranslateTransform x:Name="xform" X="-25" />
</Grid.RenderTransform>
<Border Background="StaticResource ValidationToolTipTemplateShadowBrush}" />
<Border Background="StaticResource ValidationToolTipTemplateShadowBrush}" />
<Border Background="StaticResource ValidationToolTipTemplateShadowBrush}" />
<Border Background="StaticResource ValidationToolTipTemplateShadowBrush}" />
<Border Background="StaticResource ValidationErrorElement}" />
<Border>
<TextBlock Forground="{StaticResource LightBrush}" Text="{Binding (Validation.Errors).CurrentItem.ErrorContent}" UseLayoutRounding="false" />
</Border>
</Grid>
</ControlTemplate>
When i remove Validation.ErrorTemplate of TextBox style, it show default validation. But when i use template don't show validation.
EDIT
I use this for set Validation.ErrorTemplate
Upvotes: 0
Views: 694
Reputation: 2772
here is a somethings that in my opinion can help you; TRY to use the AdornedElementPlaceholder in your ControlTemplate, it helped me before. Here is the my ControlTemplate example (a tooltip will display the error).
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<Grid DockPanel.Dock="Right" Width="16" Height="16" VerticalAlignment="Center" Margin="3 0 0 0">
<Ellipse Width="16" Height="16" Fill="Red" ToolTip="{Binding ElementName=AdornedElementPlaceholder, Path=AdornedElement.(Validation.Errors).CurrentItem.ErrorContent}"/>
<Ellipse Width="3" Height="8" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0 2 0 0" Fill="White"/>
<Ellipse Width="2" Height="2" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="0 0 0 2" Fill="White"/>
</Grid>
<Border BorderBrush="Red" BorderThickness="2" CornerRadius="2">
<AdornedElementPlaceholder x:Name="AdornedElementPlaceholder"/>
</Border>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Regards,
Upvotes: 1