简体   繁体   English

如何更新Validation.HasError属性以进行用户输入验证?

[英]How Validation.HasError property is updated for user input validation?

In this tutorial there is a text box that shows a pink background for invalid data. 本教程中,有一个文本框,显示粉红色背景表示无效数据。 This is the wpf code: 这是wpf代码:

<TextBox Text="{Binding Aid,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay,ValidatesOnDataErrors=True}" 
             Canvas.Left="95" Canvas.Top="60" Width="297">

<TextBox.Style>
            <Style TargetType="TextBox">
                <Style.Triggers>
                    <Trigger  Property="Validation.HasError" Value="True">
                        <Setter Property="Background" Value="Pink"/>
                        ...
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TextBox.Style>

        <Validation.ErrorTemplate>
            <ControlTemplate>                    
                <StackPanel>
                    <AdornedElementPlaceholder x:Name="textBox" ToolTip="{Binding [0].ErrorContent}"/>
                </StackPanel>
            </ControlTemplate>
        </Validation.ErrorTemplate>

    </TextBox>

But I don't get how Validation.HasError is updated as the user inputs the value? 但是我不知道如何在用户输入值时更新Validation.HasError?

This sample project takes advantage of IDataErrorInfo interface which makes data validation very simple. 该示例项目利用了IDataErrorInfo接口,该接口使数据验证非常简单。 This link will describe it in details . 该链接将对其进行详细描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM