DatePickerDateValidationErrorEventArgs DatePickerDateValidationErrorEventArgs DatePickerDateValidationErrorEventArgs DatePickerDateValidationErrorEventArgs Class

Definición

Proporciona datos para el evento 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
Herencia
DatePickerDateValidationErrorEventArgsDatePickerDateValidationErrorEventArgsDatePickerDateValidationErrorEventArgsDatePickerDateValidationErrorEventArgs

Ejemplos

En el ejemplo siguiente se crea un DatePicker que muestra las fechas de agosto de 2009 y especifica que no se puede seleccionar cada el sábado y el domingo.The following example creates a DatePicker that displays the dates in August 2009 and specifies that each Saturday and Sunday is not selectable. El DatePicker controla la DateValidationError eventos.The DatePicker handles the DateValidationError event. Si el usuario escribe una fecha que no es seleccionable, en el ejemplo se muestra un mensaje.If the user enters a date that is not selectable, the example displays a message. Si el usuario escribe el texto que no es una fecha válida, se produce una excepción.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

Comentarios

El DatePicker.DateValidationError evento tiene lugar cuando DatePicker.Text está establecido en un valor que no se puede interpretar como una fecha o cuando no se puede seleccionar la fecha.The 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. Puede suscribirse a este evento y especificar si se produce una excepción al establecer el ThrowException propiedad.You can subscribe to this event and specify whether an exception is raised by setting the ThrowException property. Si DatePickerDateValidationErrorEventArgs.ThrowException es true, se produce una de las siguientes excepciones:If DatePickerDateValidationErrorEventArgs.ThrowException is true, one of the following exceptions is raised:

Tipo de excepciónException type CondiciónCondition
FormatException No se puede analizar el texto escrito en una fecha válida y no se suprime la excepción.The text entered cannot be parsed to a valid date, and the exception is not suppressed.
ArgumentOutOfRangeException Analiza el texto escrito en una fecha que no es seleccionable.The text entered parses to a date that is not selectable.

Si DatePickerDateValidationErrorEventArgs.ThrowException es false, la aplicación continúa la ejecución como de costumbre.If DatePickerDateValidationErrorEventArgs.ThrowException is false, the application continues execution as usual.

Constructores

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

Inicializa una nueva instancia de la clase DatePickerDateValidationErrorEventArgs.Initializes a new instance of the DatePickerDateValidationErrorEventArgs class.

Propiedades

Exception Exception Exception Exception

Obtiene la excepción inicial asociada al evento DateValidationError.Gets the initial exception associated with the DateValidationError event.

Text Text Text Text

Obtiene o establece el texto que generó el evento DateValidationError.Gets or sets the text that caused the DateValidationError event.

ThrowException ThrowException ThrowException ThrowException

Obtiene o establece un valor que indica si debe producirse Exception.Gets or sets a value that indicates whether Exception should be thrown.

Métodos

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

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

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

Sirve como la función hash predeterminada.Serves as the default hash function.

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

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

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

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

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

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Se aplica a