With the final release of the Windows Phone 7 Development tools there was also a release of the WP7 Control Toolkit which provides us a set of standard controls such as:
- GestureService/GestureListener
- ContextMenu
- DatePicker
- TimePicker
- ToggleSwitch
- WrapPanel
The control we want to focus on here is the DatePicker. With the DatePicker control there is now a standard UX control which fits the design metaphor of WP7 (seen below).
Now that we have this new control how do we use it in our applications? The great news for you is that using is dead simple.
- Make sure you download and install the toolkit from codeplex
- Add a reference to the Microsoft.Phone.Controls.Toolkit assembly in your project
- In your xaml class make sure you add a reference to the DatePicker assembly as follows
xmlns:Controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" - In your xaml class make sure you reference the DatePicker as follows
<Controls:DatePicker /> - Now you have the DatePicker up and running.
Of course the above is the bare minimum you need to get the picker working. But what if I want to:
- Set a default value
- Bind to the value of the control
- Handle the value changed event (this gives you access to the original value and the new value)
To set the default value (with no binding) you can do the following:
<Controls:DatePicker Value="01/01/2000" />
To Bind to the value you can do the following:
<Controls:DatePicker Value="{Binding DateValue, Mode=TwoWay}" />
To Handle the value changed event you can do the following:
<Controls:DatePicker ValueChanged="DatePicker_ValueChanged" />
As you can see using the DatePicker is pretty painless and easy.
Till next time,
Posted
09-19-2010 5:49 AM
by
Derik Whittaker