How to suppress validation when nothing is entered

前端 未结 8 1339
醉梦人生
醉梦人生 2020-12-13 04:40

I use WPF data binding with entities that implement IDataErrorInfo interface. In general my code looks like this:

Business entity:

p         


        
8条回答
  •  感情败类
    2020-12-13 04:58

    Maybe it's an option for you, to shift your validation to the View: Instead of implementing IDataErrorInfo, you can enable NotifyOnValidationError in your binding and add a ValidationRule that does the check. For ValidationRules there is a standard way to control, if the rule should be applied when the object changes (not the property value directly)

    This will already provide visual feedback to the user (ErrorTemplate will be applied). If you need more, e.g. disable some buttons etc, you can wire up the Validation.Error-Event of your view to your ViewModel or BusinessEntity, s.th. you can identify there, if any error is present.

提交回复
热议问题