/// <summary> /// Input text is parsed in the correct format and changed into a /// DateTime object. If the text can not be parsed TextParseError Event /// is thrown. /// </summary> /// <param name="text">Inherited code: Requires comment.</param> /// <returns> /// IT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE /// DATETIME VALUE IF IT IS VALID. /// </returns> private DateTime?ParseText(string text) { DateTime newSelectedDate; // TryParse is not used in order to be able to pass the exception to // the TextParseError event try { newSelectedDate = DateTime.Parse(text, DateTimeHelper.GetCurrentDateFormat()); if (Calendar.IsValidDateSelection(this._calendar, newSelectedDate)) { return(newSelectedDate); } else { var dateValidationError = new CalendarDatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException(nameof(text), "SelectedDate value is not valid."), text); OnDateValidationError(dateValidationError); if (dateValidationError.ThrowException) { throw dateValidationError.Exception; } } } catch (FormatException ex) { CalendarDatePickerDateValidationErrorEventArgs textParseError = new CalendarDatePickerDateValidationErrorEventArgs(ex, text); OnDateValidationError(textParseError); if (textParseError.ThrowException) { throw textParseError.Exception; } } return(null); }
/// <summary> /// Raises the /// <see cref="E:Avalonia.Controls.CalendarDatePicker.DateValidationError" /> /// event. /// </summary> /// <param name="e"> /// A /// <see cref="T:Avalonia.Controls.CalendarDatePickerDateValidationErrorEventArgs" /> /// that contains the event data. /// </param> protected virtual void OnDateValidationError(CalendarDatePickerDateValidationErrorEventArgs e) { DateValidationError?.Invoke(this, e); }