There is a WPF Window (Window) with a huge pile of fields and their validation system based on IDataErrorInfo. The task is to allow the user to save the window data and to make DialogResult = true for him even with invalid fields, but if there is at least one invalid field, then tick the corresponding flag.

Tell me, how easy is it in the handler for pressing the "OK" button (closes the window) to check for invalid fields?

    1 answer 1

    It seems that due to the fact that IDataErrorInfo processes only one error at a time, you will have to do this in a VM construct:

    public string this[string columnName] { get { string error = String.Empty; switch (columnName) { case "RelationOther": if (!string.IsNullOrEmpty(RelationOther) && !RelationTypeMap[10]) error = "Ошибка! Указание описания не требуется"; break; case "ChildsNum": if ((SexMap[0] || FullOld < 15) && (ChildsNum ?? 0) > 0) error = "Ошибка! Количество детей указывают только женщины от 15 лет и старше"; break; case "ChildBirthDate": if ((SexMap[0] || FullOld < 15) && ChildBirthDate != null) error = "Ошибка! Дату рождения первого ребенка указывают только женщины от 15 лет и старше"; break; } return error; } } public string Error => string.Empty; public bool IsValid => Errors.Any(e => string.IsNullOrEmpty(e)); public List<string> Errors => new List<string>() { this["RelationOther"], this["ChildsNum"], this["ChildBirthDate"] }; #endregion 

    Then the isValid property will indicate that there are validation errors in the window at the moment.

    Does anyone know a better solution?