Επεξεργασία

Κοινή χρήση μέσω


DatePicker.Text Property

Definition

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

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

Property Value

The text displayed by the DatePicker. The default is an empty string.

Examples

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>

Remarks

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.

Dependency Property Information

Identifier field TextProperty
Metadata properties set to true None

XAML Attribute Usage

<DatePicker Text="dateTimeString"/>  

XAML Values

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

Applies to

See also