Export (0) Print
Expand All

DatePicker.Text Property

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

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

public string Text { get; set; }
<DatePicker Text="dateTimeString"/>

XAML Values

dateTimeString

A date that is in one of the formats that are listed in the DateTime XAML Syntax topic.

Property Value

Type: System.String
The text displayed by the DatePicker. The default is an empty string.

Identifier field

TextProperty

Metadata properties set to true

None

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. While the Text property can be set to any string that can be parsed by the Parse method date, the format of the string that is returned depends on the value of the CultureInfo.CurrentCulture property. This means that the DatePicker might display a string that is different than what the user typed.

If Text is set to a date that is selectable and valid, the DateValidationError event occurs. If you handle the DateValidationError event and set the ThrowException property to true, a FormatException or ArgumentOutOfRangeException is raised.

The following example creates a DatePicker that has the date August 10, 2009 selected. The example also binds the DatePicker.Text property to a TextBlock. Because the SelectedDateFormat property is set to Long, the DatePicker and TextBlock displays the date using unabbreviated days of the week and month names even if the user enters a short form of a date.

<StackPanel>
  <DatePicker Name="datePicker"
              SelectedDate="8/10/09"
              SelectedDateFormat="Long"/>

  <TextBlock Text="{Binding ElementName=datePicker, Path=Text}"/>
</StackPanel>

.NET Framework

Supported in: 4.5.2, 4.5.1, 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