Controls are where it's at these days in the programming world. By using them you maximize re-use, enhance productivity, and avoid building custom functionality. Plus, when you need a control to do something different you can always extend it rather than writing everything from scratch.
If you've used ASP.NET AJAX then you've likely used controls from toolkits such as the ASP.NET AJAX Control Toolkit in your applications. Microsoft has also released a Silverlight Toolkit with new controls and functionality that can be used in Silverlight 2 applications. The controls are grouped into "quality bands" with the existing controls currently fitting into either the "Preview" or "Stable" bands. Additional information about quality bands and the toolkit controls can be found on Shawn Burke's blog.
Controls included in the Silverlight Toolkit include:
- AutoCompleteBox
- ButtonSpinner
- Chart
- DockPanel
- Expander
- HeaderedItemControl
- HeaderedContentControl
- ImplicitStyleManager
- Label
- NumericUpDown
- TreeView
- ViewBox
- WrapPanel
The new controls live in the Microsoft.Windows.Controls.dll assembly which contains several namespaces such as Microsoft.Windows.Controls (where most of the controls live) and Microsoft.Windows.Controls.DataVisualization.Charting (where the charting control and related classes live). To get started using them you'll need to reference the Microsoft.Windows.Controls assembly provided in the toolkit and then add the controls to your Visual Studio 2008 Toolbox by right-clicking on it and selecting "Choose Items". Select the Silverlight Components tab, browse to the assembly and then check the checkbox next to the controls you'd like to add and then drag them into a Silverlight 2 XAML file. This will add the proper namespace onto the UserControl root element as shown next:
<UserControl xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls" x:Class="..."> </UserControl>
In this article, I discuss a few of the new controls that I personally find quite useful and show what they're are capable of doing. Future articles will drill into different controls and demonstrate additional details about how they can be used.