WPF Binding : Use DataAnnotations for ValidationRules

前端 未结 5 560
眼角桃花
眼角桃花 2020-12-09 04:59

I have read a lot of Blog post on WPF Validation and on DataAnnotations. I was wondering if there is a clean way to use DataAnnotations as Va

5条回答
  •  感情败类
    2020-12-09 05:48

    Sounds good Aaron. I'm just into WPF and will study databindings next week at work ;) So cannot completely judge your answer...

    But with winforms I have used Validation Application Block from the Entlib and implemented IDataErrorInfo (actually IDXDataErrorInfo because we work with DevExpress controls) on a base entity (business object) and that works pretty fine!

    It's a bit more sophisticated than the solution you sketched in this way that you place your validation logic on the object and not in the interface implementation. Making it more OOP and maintainable. At the ID(XD)ataErrorInfo I just call Validation.Validate(this), or even better get the validator for the property that the interface is called for and validate the specific validator. Don't forget to call the [SelfValidation] as well because of validation for combinations of properties ;)

提交回复
热议问题