Cloud Training (Online)

DatePicker in Silverlight Toolkit

The DatePicker is a control that is part of the Silverlight Toolkit for Windows Phone .

The DatePicker control includes a TextBox and Date Selection form .

When the user taps on the TextBox , a form to select the date , month and year is shown and on the click of the OK icon in the Application Bar of the Date Selection form , the textbox will be filled with the selected date .

To add the DatePicker control in the Silverlight Toolkit , just drag and drop the DatePicker control from the Visual Studio Toolbox . Make sure that you have installed the silverlight toolkit and have included the controls to the Visual Studio Toolbox .

If you are trying to create the DatePicker control dynamically , you should add the reference of the Microsoft.Phone.Controls.Toolkit.dll to your Windows Phone App .

The XAML code of the DatePicker control will look like this

<toolkit:DatePicker Height=”74″ HorizontalAlignment=”Left” Margin=”25,214,0,0″ Name=”datePicker1″ VerticalAlignment=”Top” Width=”406″ />

You can add the DatePicker control dynamically from the codebehind .

1. Add the name space Microsoft.Phone.Controls

using Microsoft.Phone.Controls;

2. Create an instance of the DatePicker control and add it to the container / panel

DatePicker picker = new DatePicker();

3. Run the Windows Phone App , you should see a textbox , tap on it to select the date …

4. The selected date can be found via the Value or ValueString property of the DatePicker control

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.