Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Silverlight applications are often composed of many separate user controls. In this movie I'll show you how to add additional user controls to your project and how to change the startup control. I'm inside Visual Studio and I've opened this Solution called CreateSilverlightControl. Now, this is a simple Silverlight application and I've decided not to create the companion website. It has one user control in it called MainPage.xaml. Let me address the confusing default naming that occurs in Silverlight before I go any further. In the earlier versions of Silverlight, due to historical reasons, people often used the term Silverlight Pages.
This is in keeping with the traditional names for Web items, for example, webpage or Java page. In reality, however, a Silverlight Page is a user control. The tradition has endured, and both Visual Studio and Expression Blend create user controls but name it MainPage. Let's see what I'm talking about. If I double-click on this MainPage.xaml file and look at this top line of xaml, you'll see that it says UserControl. So the type that is being used to generate this UI is a user control, even though it's named MainPage.
Now, to make things more confusing, you can go and add different kinds of UI elements to a Silverlight project. I'll right-click on my project and choose Add>New Item. Now, another way I could do this is to go to my Project Menu and choose Add>New Item. This lists some of the different kinds of items you can add to your project. Here is the Silverlight User Control, but look down here. There's also something called as Silverlight Page. The Silverlight Page is a special kind of control that's used with the Silverlight Navigation System. You have to use this with any Silverlight Navigation application.
There's also another kind of window called the Silverlight Child Window. For this movie I'm going to concentrate on this first one, Silverlight User Control. I'm going to create a brand-new User Control, I'm going to give it a better name than SilverlightControl1, I'm going to call this About, and then I'm going to click on the Add button. Over here in the Solution Explorer you'll see there is now a new node called About.xaml. If I double-click on it, it loads it into the Designer surface. Since I have two different Silverlight Controls, I have to tell the Silverlight engine which one to run as my startup.
Currently it's going to run MainPage.xaml; I would rather it ran About .xaml as my startup page. Before I do this, I would like add a text block to this so I can tell which control is which. To do that I can go to my Toolbox, take my TextBlock and drag it over to the Designer surface, and then, I can come over here to my Properties window and choose Text and type in new text, About. I'm going to change my startup control and the place that I do that is inside my App.xaml file. App.xaml is a global location for events and properties and settings.
I'm going to open up this node and then double-click on App.xaml.cs, and then in the Application Startup event procedure I'm going to change this Line 17 so it says the RootVisual for the Silverlight Application is no longer the Main control, but is the About control. I'm ready to see if this works. I will go to Build and compile my application, and then I'm going to run the application by pressing F5, which will run the application and attach the debugger. That's how easy it is to add your own user controls to a project.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101284 Viewers
61 Video lessons · 88043 Viewers
71 Video lessons · 71897 Viewers
56 Video lessons · 103729 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.