我有几个文本框与自定义验证程序:
(我不介意如果“错误”的数据发送回对象(属性是字符串),我只需要防止功能如果有错误,所以如果绑定是不是那种验证请告诉正确的位置的按钮。我就像Validation.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" />
这里可能重复:http://stackoverflow.com/questions/231052/using-wpf-validation-rules-and-disabling-a-save - 按钮 – Damascus
在那里的帖子不回答问题... – anderi