TextBox
这是我要验证的元素的标记:
<StackPanel Margin="7">
<Label x:Name="lblPrompt" Margin="7,12,7,5" Target="{Binding ElementName=txtInput}" />
<TextBox x:Name="txtInput" Margin="7,0,7,7" Validation.ErrorTemplate="{StaticResource ErrTemplate}" />
<UniformGrid Rows="1" Columns="2" HorizontalAlignment="Right" Width="Auto" Margin="7,7,7,3">
<Button x:Name="btnOK" Content="_OK" Padding="2" Margin="0,0,7,0" Background="BlanchedAlmond" Click="btnOK_Click" />
<Button x:Name="btnCancel" Content="_Cancel" Padding="2" Margin="7,0,7,0" IsCancel="True" Background="BlanchedAlmond" Click="btnCancel_Click" />
</UniformGrid>
</StackPanel>
并TextBox's error template
定义如下:
<ControlTemplate x:Key="ErrTemplate">
<StackPanel Orientation="Horizontal">
<AdornedElementPlaceholder x:Name="adorner" />
<TextBlock Text="{Binding ElementName=adorner,
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" Background="Red" Foreground="White" Margin="3,0,0,0" TextWrapping="Wrap" MinWidth="100" />
</StackPanel>
</ControlTemplate>
现在,当TextBox
控件上的验证失败时TextBlock
,错误模板中定义的元素只会部分显示。请看这张图片:
您能否建议如何解决?