我为应用程序添加主题。
我为textbox设置了样式,并为它设置了Validation.ErrorTemplate。
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource TextBoxValidationToolTipTemplate}"在验证模板中。
<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>当我删除Validation.ErrorTemplate of TextBox样式时,它将显示默认验证。但是当我使用模板时,不要显示验证。
编辑
我使用this来设置Validation.ErrorTemplate
发布于 2015-11-30 09:35:06
在我看来,这里有一些东西可以帮助您;尝试在您的ControlTemplate中使用AdornedElementPlaceholder,它以前帮助过我。下面是我的ControlTemplate示例(工具提示将显示错误)。
<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>致以敬意,
https://stackoverflow.com/questions/33992751
复制相似问题