简体   繁体   中英

Textbox isn't highlighting 'red' on validation error

I am binding a TextBox control to an entity called Address, which has a sub-property AddressLines. Internal validation logic has ValidationErrors for AddressLines property, but it doesn't reflect 'visually' on the control via a Red border.

    <TextBox  Text="{Binding Path=Address.AddressLines, 
                             Mode=TwoWay,
                             UpdateSourceTrigger=PropertyChanged, 
                             NotifyOnValidationError=True}" 

              ToolTip="{Binding RelativeSource={RelativeSource Self}, 
                                Path=(Validation.Errors)[0].ErrorContent}" />

If I am not wrong, it happens because the Entity Address itself isn't null and the property AddressLines is. If this is the case, how to notify the control for validation errors in case of Master-Detail errors?

The best bet is to use the IDataErrorInfo interface to customise how your objects control their validation state.

Take a look at the article here , it gives a great example. If you want a sample relevant to your code, please provide a piece of your Address etc. class, and I'll see what I can do!

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