Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 11. Creating Custom Controls > Creating User Controls

11.2. Creating User Controls

User controls enable you to build a user interface component that leverages one or more existing controls, combining them together to form a single unit. Creating a user control is as simple as adding a new Silverlight User Control item to your project and adding controls to it using the XAML designer (designing it as you would a view). In fact, as you discovered back in Chapter 4, "The Navigation Framework," the MainPage class itself is a user control. It then appears in the Toolbox, where you can drag and drop it into your views as required. You can also define properties and events in its code behind, which can be used by the views that consume the user control.

11.2.1. Creating a Simple User Control

Let's create a simple user control that includes a label and a text box together as a single component. Add a new item to your project using the Silverlight User Control item template, named FormField.xaml. Lay it out with a Label control and a TextBox control in a Grid, like so:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint