Adding controls and UI elements to a Silverlight user control is an easy task and looks like what was already described about WPF. While you go through adding controls, you can also notice how Silverlight properties are in most cases the same as WPF properties. Replace the Background
property value in the main Grid
from White
to SteelBlue
. This provides better visibility of the user control in the web browser. Notice that you can still apply brushes as in WPF. Next, add a TextBlock
control and place it at the top of the user control. Set its properties so that the foreground color is white and the font size is 24. Finally drag a Button
control from the toolbox onto the user control surface. Also notice how Visual Studio also generated the appropriate XAML code for each of the operations accomplished. To handle events, you still write event handlers as you are used to doing in other .NET applications. In this case, double-click the Button
and write the following simple handler:
It is important that Silverlight still offers the routed events infrastructure as in WPF, so basically handling events in both technologies is identical. Now press F5 to start the application with an instance of the Visual Studio debugger attached. Figure 39.4 shows how the application runs inside the web browser.
Now that you have built and run your first rich Internet application, you need to learn how Silverlight applications are packaged and deployed.
18.118.163.207