// A method that simply takes an ObservableValidator // and returns the first error from it if one exists, // otherwise returning an empty string. Unfortunately, // WinUI does not support input validation on the // UI elements, so we couldn't show the user per-field // validation, so this is the next best thing - we simply // get the first error and show them it. public static string GetFirstError(this ObservableValidator validator) { // We get the errors from the validator, passing in null // as the property name (this returns errors for every property) // then we get the first one, or null if none exist. var firstError = validator.GetErrors(null).FirstOrDefault(); // We then either return an empty string // or the error message depending on if // it exists. return(firstError != null ? firstError.ErrorMessage : ""); }
public static void ValidateProperty(ObservableValidator instance, object?value, string propertyName) { instance.ValidateProperty(value, propertyName); }