C H A P T E R  12

Creating User Controls and Custom Controls

When designing user interfaces in any technology, you ideally want to encapsulate the look and behavior of commonly used user interface elements into reusable components that you can use elsewhere in your application, or even in other applications. Creating custom controls also reduces the amount of code required in the code-behind, simplifies the XAML in your views, and helps maintain consistency in your user interface.

We already have a wide range of controls available to use from the core Silverlight control set, the Silverlight Toolkit, and open source controls on CodePlex. In addition, there are many more in the form of third-party controls from companies such as Telerik, ComponentOne, DevExpress, and Infragistics. Occasionally, however, you will find that you have specific requirements that no existing control currently provides. It's at this point that you should consider creating your own control.

There are two ways to create a reusable user interface component in Silverlight as a user control, or as a custom control. Generally, user controls simply combine multiple existing controls into a single component, while you will usually start from scratch with custom controls and provide the look and behavior yourself. In this chapter, we will look at creating and using both of these types of components. Some implementation details, such as exposing properties and events, are much the same between the two types of components, but other details and capabilities can differ greatly, particularly when it comes to styling and templating. However, let's start by simply extending an existing control to add additional behavior to it, before continuing on to focusing on how to create and use user controls and custom controls.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset