void PersistentObjectDTO_Validated(object sender, ObjectValidationEventArgs e) { ServiceLocator serviceLocator = ServiceLocator.GetActive(); if (e.IsValid) { serviceLocator.SessionState.ValidationErrors.Remove(e.Details); } else { if (!serviceLocator.SessionState.ValidationErrors.Contains(e.Details)) { serviceLocator.SessionState.ValidationErrors.Add(e.Details); } } }
/// <summary> /// Used for built-in WPF validation. /// Additionally, raises Validated event so application can react on validation appropriately. /// Standart Validation.Error event is quirky in Data Grids /// and it's behaviour has been subject to breaking changes when switching from .net 3.5 to 4.0. /// </summary> /// <param name="propertyName"></param> /// <returns></returns> public string this[string propertyName] { get { var error = new Validator().Validate(this, propertyName); string errorMessage = error == null ? null : error.ToString(); // Fire Validated event. var validationDetails = new ObjectPropertyValidationDetails(PersistentType, ID, propertyName) { ErrorMessage = errorMessage }; var validationEventArgs = new ObjectValidationEventArgs(errorMessage == null, validationDetails); var tmpValidated = Validated; if (tmpValidated != null) { tmpValidated(this, validationEventArgs); } return(errorMessage); } }