我有几个带有自定义验证器的文本框:
(如果发送回对象的数据“错误”,我并不介意(该属性是字符串),我只需要防止在出现错误时按钮的功能,所以如果绑定不是那种验证的正确位置,请告诉我。我只喜欢可以使用Validation.ErrorTemplate支持的验证.ErrorTemplate)
<ControlTemplate x:Key="validator" >
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="12pt">!</TextBlock>
<Border BorderBrush="Red" BorderThickness="1.0">
<AdornedElementPlaceholder />
</Border>
</DockPanel>
</ControlTemplate>
<TextBox Height="23" Width="150" TextWrapping="Wrap"
Validation.ErrorTemplate="{StaticResource validator}">
<TextBox.Text>
<Binding Path="StringProperty" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<local:NumbersOnly/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
如果出现任何验证错误,我该如何禁用特定的按钮?
<Button Content="DO Work" Height="57" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="234" Click="button1_Click" />