0

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

Community
  • 1
  • 1
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100

1 Answers1

1

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,

Ilan
  • 2,762
  • 1
  • 13
  • 24
  • @ar.gorgin error will be displayed by tooltip when your is over the first Ellipse object (the red circle). – Ilan Nov 30 '15 at 10:29