Export (0) Print
Expand All

DatePicker.DateValidationError Event

Occurs when Text is set to a value that cannot be interpreted as a date or when the date cannot be selected.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

member DateValidationError : IEvent<EventHandler<DatePickerDateValidationErrorEventArgs>,
    DatePickerDateValidationErrorEventArgs>
<DatePicker DateValidationError="eventhandler"/>

After the DateValidationError event occurs, if you set the DatePickerDateValidationErrorEventArgs.ThrowException property to 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.

The following example creates a DatePicker that displays the dates in August 2009 and specifies that each Saturday and Sunday is not selectable.

No code example is currently available or this language may not be supported.
<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>

The DatePicker handles the DateValidationError event, as shown in the following code. 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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft