Wpf 在禁用的文本框上禁用验证
验证程序检查输入值的格式是否正确:file.extension。不幸的是,当控件IsEnabled==false时,文本框为红色(因为内容为“”Wpf 在禁用的文本框上禁用验证,wpf,Wpf,验证程序检查输入值的格式是否正确:file.extension。不幸的是,当控件IsEnabled==false时,文本框为红色(因为内容为“” 知道如何禁用验证吗?尝试使用x:reference并将UIElement传递给验证器,但没有成功。最初的功劳归于in@ydoow的答案 当控件被禁用时,通过将Validation.ErrorTemplate设置为null的触发器可以轻松实现 属性仍在验证中,但不会通知用户验证结果 <Binding Path="AttachmentName" Up
知道如何禁用验证吗?尝试使用x:reference并将UIElement传递给验证器,但没有成功。最初的功劳归于in@ydoow的答案 当控件被禁用时,通过将
Validation.ErrorTemplate
设置为null的触发器可以轻松实现
属性仍在验证中,但不会通知用户验证结果
<Binding Path="AttachmentName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<valid:AttachmentNameValidationRule ValidationStep="RawProposedValue" ValidatesOnTargetUpdated="True"/>
</Binding.ValidationRules>
</Binding>
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}"/>
</Trigger>
</Style.Triggers>
</Style>