DatePickerDateValidationErrorEventArgs DatePickerDateValidationErrorEventArgs DatePickerDateValidationErrorEventArgs DatePickerDateValidationErrorEventArgs Class

定義

DateValidationError イベントのデータを提供します。Provides data for the DateValidationError event.

public ref class DatePickerDateValidationErrorEventArgs : EventArgs
public class DatePickerDateValidationErrorEventArgs : EventArgs
type DatePickerDateValidationErrorEventArgs = class
    inherit EventArgs
Public Class DatePickerDateValidationErrorEventArgs
Inherits EventArgs
継承
DatePickerDateValidationErrorEventArgsDatePickerDateValidationErrorEventArgsDatePickerDateValidationErrorEventArgsDatePickerDateValidationErrorEventArgs

次の例ではDatePicker 、2009年8月に日付を表示するを作成し、各土曜日と日曜日を選択できないように指定しています。The following example creates a DatePicker that displays the dates in August 2009 and specifies that each Saturday and Sunday is not selectable. DatePicker 、イベントDateValidationErrorを処理します。The DatePicker handles the DateValidationError event. ユーザーが選択できない日付を入力した場合、この例ではメッセージが表示されます。If the user enters a date that is not selectable, the example displays a message. ユーザーが有効な日付でないテキストを入力すると、例外がスローされます。If the user enters text that is not a valid date, an exception is thrown.

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.Text日付として解釈できない値に設定されている場合、または日付を選択できない場合に発生します。 DatePicker.DateValidationErrorThe DatePicker.DateValidationError event occurs when DatePicker.Text is set to a value that cannot be interpreted as a date or when the date cannot be selected. このイベントをサブスクライブし、 ThrowExceptionプロパティを設定することによって例外を発生させるかどうかを指定できます。You can subscribe to this event and specify whether an exception is raised by setting the ThrowException property. DatePickerDateValidationErrorEventArgs.ThrowExceptiontrueの場合は、次のいずれかの例外が発生します。If DatePickerDateValidationErrorEventArgs.ThrowException is true, one of the following exceptions is raised:

例外の種類Exception type 条件Condition
FormatException 入力したテキストを有効な日付に解析できません。また、例外は抑制されません。The text entered cannot be parsed to a valid date, and the exception is not suppressed.
ArgumentOutOfRangeException 入力したテキストは、選択できない日付に解析されます。The text entered parses to a date that is not selectable.

DatePickerDateValidationErrorEventArgs.ThrowExceptionfalseの場合、アプリケーションは通常どおり実行を継続します。If DatePickerDateValidationErrorEventArgs.ThrowException is false, the application continues execution as usual.

コンストラクター

DatePickerDateValidationErrorEventArgs(Exception, String) DatePickerDateValidationErrorEventArgs(Exception, String) DatePickerDateValidationErrorEventArgs(Exception, String) DatePickerDateValidationErrorEventArgs(Exception, String)

DatePickerDateValidationErrorEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the DatePickerDateValidationErrorEventArgs class.

プロパティ

Exception Exception Exception Exception

DateValidationError イベントに関連付けられた最初の例外を取得します。Gets the initial exception associated with the DateValidationError event.

Text Text Text Text

DateValidationError イベントの原因となったテキストを取得または設定します。Gets or sets the text that caused the DateValidationError event.

ThrowException ThrowException ThrowException ThrowException

Exception をスローするかどうかを示す値を取得または設定します。Gets or sets a value that indicates whether Exception should be thrown.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象