// iT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID /// <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> 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.GetDateFormat(DateTimeHelper.GetCulture(this))); if (Calendar.IsValidDateSelection(this._calendar, newSelectedDate)) { return(newSelectedDate); } else { DatePickerDateValidationErrorEventArgs dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text", System.SR.Get(SRID.Calendar_OnSelectedDateChanged_InvalidValue)), text); OnDateValidationError(dateValidationError); if (dateValidationError.ThrowException) { throw dateValidationError.Exception; } } } catch (FormatException ex) { DatePickerDateValidationErrorEventArgs textParseError = new DatePickerDateValidationErrorEventArgs(ex, text); OnDateValidationError(textParseError); if (textParseError.ThrowException && textParseError.Exception != null) { throw textParseError.Exception; } } return(null); }
/// <summary> /// 通常,当用户打开日历视图时会丢弃非法值,但可以选择填充一些文本以向用户通知发生了问题 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void datePickerDateValidationError_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { //lblError.Text = "," + e.Text + // "' is not a valid value because " + e.Exception.Message; }
private void _elementToCleanUp_TextParseError2(object sender, DatePickerDateValidationErrorEventArgs e) { e.ThrowException = false; }
private void DatePicker_DateValidationError_1(object sender, DatePickerDateValidationErrorEventArgs e) { e.ThrowException = false; }
private void DatePicker_OnDateValidationError(object?sender, DatePickerDateValidationErrorEventArgs e) { LabelError.Text = $"'{e.Text}' is not a valid value because ${e.Exception.Message}"; }
private void dateSampling_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { ((DatePicker)sender).Text = DateTime.Now.ToShortDateString(); }
private void dp_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { MessageBox.Show("Insert valide values", "Error", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// Validate DepartureDataPicker OnDateVlalidationError /// </summary> /// <param name="sender">Sender parameter</param> /// <param name="e">Event parameter</param> private void DepartureDateDatePickerOnDateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { MessageBox.Show("Invalid Date format"); }
/// <summary> /// Raises the DateValidationError event. /// </summary> /// <param name="e">A DatePickerDateValidationErrorEventArgs that contains the event data.</param> protected virtual void OnDateValidationError(DatePickerDateValidationErrorEventArgs e) { EventHandler<DatePickerDateValidationErrorEventArgs> handler = this.DateValidationError; if (handler != null) { handler(this, e); } }
// iT SHOULD RETURN NULL IF THE STRING IS NOT VALID, RETURN THE DATETIME VALUE IF IT IS VALID /// <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> 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.GetDateFormat(DateTimeHelper.GetCulture(this))); if (Calendar.IsValidDateSelection(this._calendar, newSelectedDate)) { return newSelectedDate; } else { DatePickerDateValidationErrorEventArgs dateValidationError = new DatePickerDateValidationErrorEventArgs(new ArgumentOutOfRangeException("text", SR.Get(SRID.Calendar_OnSelectedDateChanged_InvalidValue)), text); OnDateValidationError(dateValidationError); if (dateValidationError.ThrowException) { throw dateValidationError.Exception; } } } catch (FormatException ex) { DatePickerDateValidationErrorEventArgs textParseError = new DatePickerDateValidationErrorEventArgs(ex, text); OnDateValidationError(textParseError); if (textParseError.ThrowException && textParseError.Exception != null) { throw textParseError.Exception; } } return null; }
private void DatePicker_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { (sender as DatePicker).SelectedDate = null; }
private void DatePicker_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { ErrorLabel.Text = string.Format("'{0}' is not a valid value because {1}", e.Text, e.Exception.Message); }
private void datePicker1_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { MessageBox.Show(e.Text + " 该日期非法 " + e.Exception.Message); }
private void DatePicker_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { }
private void dpStop_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e) { MessageBox.Show("用户输入了一个非法日期!" + e.Text); }