DatePicker Class Home
This page is specific to:.NET Framework Version:Silverlight 34.0
.NET Framework Class Library
DatePicker Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents a control that allows the user to select a 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
Syntax

'Usage

Dim instance As DatePicker

'Declaration

<TemplatePartAttribute(Name := "PART_TextBox", Type := GetType(DatePickerTextBox))> _
<TemplatePartAttribute(Name := "PART_Popup", Type := GetType(Popup))> _
<TemplatePartAttribute(Name := "PART_Button", Type := GetType(Button))> _
<TemplatePartAttribute(Name := "PART_Root", Type := GetType(Grid))> _
Public Class DatePicker _
    Inherits Control
<DatePicker .../>
Remarks

The DatePicker control allows the user to select a date by either typing it into a text field or by using a drop-down Calendar control.

Many of a DatePicker control's properties are for managing its built-in Calendar, and function identically to the equivalent property in Calendar. In particular, the DatePicker..::.IsTodayHighlighted, DatePicker..::.FirstDayOfWeek, DatePicker..::.BlackoutDates, DatePicker..::.DisplayDateStart, DatePicker..::.DisplayDateEnd, DatePicker..::.DisplayDate, and DatePicker..::.SelectedDate properties function identically to their Calendar counterparts. For more information, see Calendar.

Users can type a date directly into a text field, which sets the Text property. If the DatePicker cannot convert the entered string to a valid date, the DateValidationError event will be raised. By default, this causes an exception, but an event handler for DateValidationError can set the ThrowException property to false and prevent an exception from being raised.

Examples

The following illustration shows a DatePicker.

DatePicker Control

DatePicker control

The following example creates the DatePicker shown in the previous illustration. The DatePicker does the following:

  • Displays the date using unabbreviated days of the week and month names.

  • Limits the drop-down calendar to display dates only in the year 2009.

  • Displays Monday as the first day of the week.

Dim datePickerFor2009 As New DatePicker()
datePickerFor2009.SelectedDate = New DateTime(2009, 3, 23)
datePickerFor2009.DisplayDateStart = New DateTime(2009, 1, 1)
datePickerFor2009.DisplayDateEnd = New DateTime(2009, 12, 31)
datePickerFor2009.SelectedDateFormat = DatePickerFormat.[Long]
datePickerFor2009.FirstDayOfWeek = DayOfWeek.Monday

' root is a Panel that is defined elsewhere. 
root.Children.Add(datePickerFor2009)


<!-- A DatePicker that has March 23, 2009 selected and 
     displays the Long date format. -->
<DatePicker SelectedDateFormat="Long" SelectedDate="3/23/09"
            DisplayDateStart="1/01/09" DisplayDateEnd="12/31/09" 
            FirstDayOfWeek="Monday"/>
Inheritance Hierarchy

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows.Media..::.Visual
        System.Windows..::.UIElement
          System.Windows..::.FrameworkElement
            System.Windows.Controls..::.Control
              System.Windows.Controls..::.DatePicker
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View