Chapter 12. Programming Custom Silverlight Controls and Libraries
Silverlight is one of the most dynamic languages. It comes with a rich set of controls; however, it is very simple to extend the functionality of existing controls and even create new controls with new functionality. Creating custom controls in Silverlight is a great way to make your Silverlight applications more rich and unique.
One of the most common problems that developers face is how to reuse their code. Typically, the best answer to that is to create some sort of library that can be consumed by multiple applications or at least multiple times in the same application.
Silverlight has a couple of different solutions that allow developers to write reusable code. One solution is to add another Silverlight UserControl
to a project and then provide the functionality there. A second and better solution is to create a Silverlight class library and implement the UI and functionality there. The following sections describe building and implementing custom Silverlight controls using each of these methods.
Creating Custom Silverlight Controls in Applications
When you build Silverlight applications, you will notice the need to repeat several of the same steps for several controls of the same type. For example, if you create custom buttons you need to either repeat all of the XAML required for the custom button in the XAML file or implement code in the code-behind page to repetitively build the functionality for each button.
Get Silverlight™ 2 Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.