Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 在禁用的文本框上禁用验证_Wpf - Fatal编程技术网

Wpf 在禁用的文本框上禁用验证

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

验证程序检查输入值的格式是否正确:file.extension。不幸的是,当控件IsEnabled==false时,文本框为红色(因为内容为“”


知道如何禁用验证吗?尝试使用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>