コード例 #1
0
ファイル: DatePicker.cs プロジェクト: superdino123/WPFText
        // 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);
        }
コード例 #2
0
ファイル: Simple.xaml.cs プロジェクト: lei130102/GuidelinesVS
 /// <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;
 }
コード例 #3
0
 private void _elementToCleanUp_TextParseError2(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     e.ThrowException = false;
 }
コード例 #4
0
 private void DatePicker_DateValidationError_1(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     e.ThrowException = false;
 }
コード例 #5
0
 private void DatePicker_OnDateValidationError(object?sender, DatePickerDateValidationErrorEventArgs e)
 {
     LabelError.Text = $"'{e.Text}' is not a valid value because ${e.Exception.Message}";
 }
コード例 #6
0
 private void dateSampling_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     ((DatePicker)sender).Text = DateTime.Now.ToShortDateString();
 }
コード例 #7
0
ファイル: DatePickerTest.cs プロジェクト: dfr0/moon
 private void _elementToCleanUp_TextParseError2(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     e.ThrowException = false;
 }
コード例 #8
0
 private void dp_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     MessageBox.Show("Insert valide values", "Error", MessageBoxButton.OK, MessageBoxImage.Information);
 }
コード例 #9
0
 /// <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");
 }
コード例 #10
0
 /// <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);
     }
 }
コード例 #11
0
        // 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;
        }
コード例 #12
0
ファイル: DateWindow.xaml.cs プロジェクト: Eleus-2008/ToDoApp
 private void DatePicker_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     (sender as DatePicker).SelectedDate = null;
 }
コード例 #13
0
 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);
 }
コード例 #14
0
ファイル: MainWindow.xaml.cs プロジェクト: AOYLAOTANG/WPF
 private void datePicker1_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     MessageBox.Show(e.Text + " 该日期非法 " + e.Exception.Message);
 }
コード例 #15
0
ファイル: ControlTest.xaml.cs プロジェクト: WMH0304/JvGeLiZi
        private void DatePicker_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
        {

        }
コード例 #16
0
 private void dpStop_DateValidationError(object sender, DatePickerDateValidationErrorEventArgs e)
 {
     MessageBox.Show("用户输入了一个非法日期!" + e.Text);
 }