Share via


DatePicker.Text Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the text that is displayed by the DatePicker, or sets the selected date.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)

Syntax

'Declaration
Public Property Text As String
public string Text { get; set; }
<sdk:DatePicker Text="dateTimeString"/>

XAML Values

  • dateTimeString
    A date specified in the format yyyy/mm/dd. The mm and dd components must always consist of two characters, with a leading zero if necessary. For instance, the month of May should be specified as 05.

Property Value

Type: System.String
The text displayed by the DatePicker.

Exceptions

Exception 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.

Remarks

Dependency property identifier field: TextProperty

A user can set the SelectedDate of a DatePicker by typing a date into its text box. The DatePicker attempts to parse any string entered into this property as a date. If the string cannot be parsed as a date, this property is set to the last valid date, or to the default text if no valid date has been entered.

In addition, an exception is generated. However, before the exception is thrown, the DatePicker raises the DateValidationError event, which can set the ThrowException property in the DatePickerDateValidationErrorEventArgs. If that property is set to false, the exception is not thrown. If you want to resolve validation errors yourself, you can handle this event and set ThrowException to false in order to suppress the exception.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.