SIGN UP MEMBER LOGIN:    
ARTICLE

WPF DateTimePicker

Posted by Mahesh Chand Articles | WPF with C# September 17, 2011
This article demonstrates how to use a DateTimePicker control in WPF with the help of XAML and C#.
Reader Level:
Download Files:
 

WPF DateTimePicker Control

The DateTimePicker control is an addition to the DatePicker control that allows users to pick a date and time using a calendar. This article demonstrates how to use a DateTimePicker control in WPF with the help of XAML and C#.

Creating a DateTimePicker

The DateTimePicker element represents a WPF DateTimePicker control in XAML. 

<wpfx:DateTimePicker /> 

The DateTimePicker control is defined in the System.Windows.Controls namespace. When you drag and drop a DateTimePicker control from Toolbox to the page, you will notice the code listed in Listing 1 is added to the XAML file for the DateTimePicker control. 

<wpfx:DateTimePicker Height="25" HorizontalAlignment="Left" Margin="42,26,0,0" Name="DateTimePicker1" VerticalAlignment="Top" Width="250" /> 

Listing 1

The output looks like Figure 1. You can click on the up and down arrows to change the day and time and also can use the drop down arrow to load the monthly calendar view. You can also change the time from the bottom of the control.

 

DateTimePicker1.jpg

Figure 1

 

Text Property

The Text property represents the selected date and time in a string format.

MessageBox.Show(DateTimePicker1.Text);

 

Related Links

Here is a list of some more related links

Summary

In this article, we saw how to use a DateTimePicker control in WPF with the help of XAML and C#


Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor