DatePickerDateValidationErrorEventArgs 클래스

정의

DateValidationError 이벤트에 대한 데이터를 제공합니다.

public ref class DatePickerDateValidationErrorEventArgs : EventArgs
public class DatePickerDateValidationErrorEventArgs : EventArgs
type DatePickerDateValidationErrorEventArgs = class
    inherit EventArgs
Public Class DatePickerDateValidationErrorEventArgs
Inherits EventArgs
상속
DatePickerDateValidationErrorEventArgs

예제

다음 예제에서는 DatePicker 2009 년 8 월의에서 날짜를 표시 하 고 각 토요일과 일요일 선택할 수 있는 임을 지정 합니다. 합니다 DatePicker 핸들을 DateValidationError 이벤트입니다. 사용자가 선택할 수 있는 날짜를 입력 하는 경우이 예제에서는 메시지를 표시 합니다. 사용자가 유효한 날짜가 아닌 텍스트를 입력 하는 경우 예외가 throw 됩니다.

DatePicker datePickerWithBlackoutDates = new DatePicker();

datePickerWithBlackoutDates.DisplayDateStart = new DateTime(2009, 8, 1);
datePickerWithBlackoutDates.DisplayDateEnd = new DateTime(2009, 8, 31);
datePickerWithBlackoutDates.SelectedDate = new DateTime(2009, 8, 10);

datePickerWithBlackoutDates.BlackoutDates.Add(
    new CalendarDateRange(new DateTime(2009, 8, 1), new DateTime(2009, 8, 2)));
datePickerWithBlackoutDates.BlackoutDates.Add(
    new CalendarDateRange(new DateTime(2009, 8, 8), new DateTime(2009, 8, 9)));
datePickerWithBlackoutDates.BlackoutDates.Add(
    new CalendarDateRange(new DateTime(2009, 8, 15), new DateTime(2009, 8, 16)));
datePickerWithBlackoutDates.BlackoutDates.Add(
    new CalendarDateRange(new DateTime(2009, 8, 22), new DateTime(2009, 8, 23)));
datePickerWithBlackoutDates.BlackoutDates.Add(
    new CalendarDateRange(new DateTime(2009, 8, 29), new DateTime(2009, 8, 30)));

datePickerWithBlackoutDates.DateValidationError +=
    new EventHandler<DatePickerDateValidationErrorEventArgs>(DatePicker_DateValidationError);

// root is a Panel that is defined elsewhere.
root.Children.Add(datePickerWithBlackoutDates);
Dim datePickerWithBlackoutDates As New DatePicker()

datePickerWithBlackoutDates.DisplayDateStart = New DateTime(2009, 8, 1)
datePickerWithBlackoutDates.DisplayDateEnd = New DateTime(2009, 8, 31)
datePickerWithBlackoutDates.SelectedDate = New DateTime(2009, 8, 10)

datePickerWithBlackoutDates.BlackoutDates.Add( _
    New CalendarDateRange(New DateTime(2009, 8, 1), New DateTime(2009, 8, 2)))

datePickerWithBlackoutDates.BlackoutDates.Add( _
    New CalendarDateRange(New DateTime(2009, 8, 8), New DateTime(2009, 8, 9)))

datePickerWithBlackoutDates.BlackoutDates.Add( _
    New CalendarDateRange(New DateTime(2009, 8, 15), New DateTime(2009, 8, 16)))

datePickerWithBlackoutDates.BlackoutDates.Add( _
    New CalendarDateRange(New DateTime(2009, 8, 22), New DateTime(2009, 8, 23)))

datePickerWithBlackoutDates.BlackoutDates.Add( _
    New CalendarDateRange(New DateTime(2009, 8, 29), New DateTime(2009, 8, 30)))

AddHandler datePickerWithBlackoutDates.DateValidationError, _
    AddressOf DatePicker_DateValidationError

' root is a Panel that is defined elsewhere. 
root.Children.Add(datePickerWithBlackoutDates)
<DatePicker Name="datePickerWithBlackoutDates"
            DisplayDateStart="8/1/09"
            DisplayDateEnd="8/31/09"
            SelectedDate="8/10/09"
            DateValidationError="DatePicker_DateValidationError">
  <DatePicker.BlackoutDates>
    <CalendarDateRange Start="8/1/09" End="8/2/09"/>
    <CalendarDateRange Start="8/8/09" End="8/9/09"/>
    <CalendarDateRange Start="8/15/09" End="8/16/09"/>
    <CalendarDateRange Start="8/22/09" End="8/23/09"/>
    <CalendarDateRange Start="8/29/09" End="8/30/09"/>
  </DatePicker.BlackoutDates>
</DatePicker>
// If the text is a valid date, but a part of the 
// BlackoutDates collection, show a message.
// If the text is not a valid date, thow an exception.
private void DatePicker_DateValidationError(object sender,
                DatePickerDateValidationErrorEventArgs e)
{
    DateTime newDate;
    DatePicker datePickerObj = sender as DatePicker;

    if (DateTime.TryParse(e.Text, out newDate))
    {
        if (datePickerObj.BlackoutDates.Contains(newDate))
        {
            MessageBox.Show(String.Format("The date, {0}, cannot be selected.",
                                           e.Text));
        }
    }
    else
    {
        e.ThrowException = true;
    }
}
' If the text is a valid date, but a part of the 
' BlackoutDates collection, show a message. 
' If the text is not a valid date, thow an exception. 
Private Sub DatePicker_DateValidationError(ByVal sender As Object, _
                                           ByVal e As DatePickerDateValidationErrorEventArgs)

    Dim newDate As DateTime
    Dim datePickerObj As DatePicker = TryCast(sender, DatePicker)

    If DateTime.TryParse(e.Text, newDate) Then
        If datePickerObj.BlackoutDates.Contains(newDate) Then
            MessageBox.Show([String].Format("The date, {0}, cannot be selected.", e.Text))
        End If
    Else
        e.ThrowException = True
    End If
End Sub

설명

합니다 DatePicker.DateValidationError 이벤트가 발생할 때 DatePicker.Text 날짜로 해석할 수 없는 날짜를 선택할 수 없을 경우 값으로 설정 됩니다. 이 이벤트를 구독 하 고 설정 하 여 예외를 발생시킬지 여부를 지정할 수는 ThrowException 속성입니다. 하는 경우 DatePickerDateValidationErrorEventArgs.ThrowExceptiontrue, 다음 예외 중 하나가 발생 합니다.

예외 종류 조건
FormatException 유효한 날짜 입력 한 텍스트를 구문 분석할 수 없습니다 및 예외가 표시 됩니다.
ArgumentOutOfRangeException 선택할 수 있는 날짜를 입력 한 텍스트 구문 분석 합니다.

하는 경우 DatePickerDateValidationErrorEventArgs.ThrowExceptionfalse, 애플리케이션 실행이 정상적으로 계속 합니다.

생성자

DatePickerDateValidationErrorEventArgs(Exception, String)

DatePickerDateValidationErrorEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

Exception

DateValidationError 이벤트와 관련된 초기 예외를 가져옵니다.

Text

DateValidationError 이벤트를 발생시킨 텍스트를 가져오거나 설정합니다.

ThrowException

Exception을 throw해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상