Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
WPF Date Picker Control

WPF Date Picker Control

Ratings: (0)|Views: 0 |Likes:
Published by Abhi

More info:

Published by: Abhi on Mar 12, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

05/13/2014

pdf

text

original

 
WPF DatePicker Control
A DatePicker control is used to create a visual DatePicker that let user to pick a date and fire an event on theselection of the date. This article demonstrates how to create and use a DatePicker control in WPF with the help of XAML and C#.
Creating a DatePicker
The DatePicker element represents a WPF DatePicker control in XAML.
<DatePicker/> 
The DatePicker control is defined in the System.Windows.Controls namespace. When you drag and drop aDatePicker control from Toolbox to the page, you will notice the code listed in Listing 1 is added to the XAML filefor the DatePicker control. 
<DatePickerHeight="25"HorizontalAlignment="Left"Margin="42,26,0,0" Name="datePicker1" VerticalAlignment="Top"Width="115" />  
 Listing 1
The Width and Height attributes of the DatePicker element represent the width and the height of a DatePicker. TheContent attribute represents the text of a DatePicker. The Name attribute represents the name of the control, whichis a unique identifier of a control.When you run this code, you will see a TextBox with text Select a date and when you click on this TextBox or thedate, Calendar dropdown will appear where you can select a date. The selected date will be the date in the TextBoxas you can see in Figure 1.
 
 Figure 1
 
Display Date
The DisplayDate property represents the date to display. The default is today.
IsDropDownOpen
The IsDropDownOpen property indicates if the calendar part of the DatePicker control is open or closed.
Text Property
The Text property represents the text that is displayed in the DatePicker.
Selection Date and Selection Date Format
The SelectedDate property represents the currently selected date. If multiple dates selection is true, theSelectedDates property represents a collection of currently selected dates.
BlackoutDates
The BlackoutDates property of the DatePicker class represents a collection of dates that are not available for selection. All non selection dates are marked by a cross. For example, say in March month of year 2010, we wouldlike to block dates from Jan 1
st
to Jan 7
th
and then all Sundays and the final DatePicker should look like Figure 2.
 
 Figure 2
The following code snippet adds backout dates to a DatePicker.
<DatePicker.BlackoutDates> <CalendarDateRangeStart="3/1/2010"End="3/7/2010"/>  <CalendarDateRangeStart="3/8/2010"End="3/8/2010"/>  <CalendarDateRangeStart="3/15/2010"End="3/15/2010"/>  <CalendarDateRangeStart="3/22/2010"End="3/22/2010"/>  <CalendarDateRangeStart="3/29/2010"End="3/29/2010"/> </DatePicker.BlackoutDates>
 We can achieve this by adding code listed in Listing 2. As you can see from Listing 3, the BlackoutDates.Addmethod takes a CalendarDateRange object, which is a collection of two DateTime objects. The first date is the startdate of the range and second date is the end date of the date range.
private voidSetBlackOutDates() {MonthlyCalendar.BlackoutDates.Add(new CalendarDateRange(  new DateTime(2010, 3, 1),  new DateTime(2010, 3, 7) ));MonthlyCalendar.BlackoutDates.Add(new CalendarDateRange(

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->