简体   繁体   中英

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:

<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?

This sample project takes advantage of IDataErrorInfo interface which makes data validation very simple. This link will describe it in details .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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