Choosing Silverlight Application will further give more options, such as: We can either a build a web site where our Silverlight controls will be hosted or we could just generate a HTML Page to host the control. This post focuses on building Silverlight applications by generating a HTML test page and hosting the Silverlight control. Choosing the second option of generating an HTML page, Visual Studio would generate the necessary code and the files. The Toolbox section now has a lot of new Silverlight controls. And we also have the XAML Design and Code window. Now, we are ready to design a small Silverlight Hello World program.Here is the code that we have added: Nothing fancy here. We have added a Stack Panel, an Image, a Button with a Click event, and a TextBlock. And the corresponding design looks like: If you look at the design code, it looks very similar in building WPF applications, as both WPF and Silverlight now use XAML.We can now insert the necessary code behind for the Button’s Click event to raise an Alert window. Note that we are building a browser window and thus we do not have the normal MessageBox, instead we have to use the Alert box. Our Hello World Silverlight application is now ready to launch. Building and executing the application will open the application in a browser window: The Silverlight 2 beta 1 Assemblies and Namespaces Silverlight is a cross-browser, cross-platform plug-in which is running on top of .Net framework. So what assemblies and namespaces does Silverlight use? The references tab in the Solution Explorer does show some of the familiar names: Are they same assemblies that are used in normal WPF applications? – The answer is NO. This is a stripped down version of the BIG .Net framework. We can also call it as a mini .Net framework built especially for Silverlight. Where do these assemblies reside? – These assemblies reside in the Silverlight installation folder. Traverse to the following location to view the full list of assemblies%ProgramFiles%\Microsoft Silverlight\2.0.30226.2\ These assemblies are provided by the Silverlight SDK. How are Silverlight Applications executed?Our whole project including the XAML and other sources are compiled into assemblies (.dlls). That’s the reason we see that every Silverlight project will always be an UserControl: This assembly is then combined with the assemblies that our project uses and packaged into a .XAP (pronounced as ZAP) file. This XAP is then read by the Silverlight runtime in the browser and rendered accordingly. If we look into the Output while building our Silverlight project, we can see that it is indeed packaged into XAP file: Traversing to the ClientBin folder in our project location, we can see the XAP file generated: Let us do something interesting. As told earlier, the XAP file is nothing but an archive, in other words, a ZIP file. Copy the HelloWorld.xap to your favorite location and rename the extension .xap to .zip Now you can extract the contents from the archive and see what is inside. What we see in the archive is the control assembly and the other assemblies that the control uses. Exploring the AppManifest file, we could see that it has a Deployment class which holds our control and other assemblies. More about Deployment class and its’ members can be found here.This is the end of Part 1 of building Silverlight applications with Visual Studio 2008. The next part would introduce some of the default Silverlight controls available with the SDK. The sample application can be downloaded here:
HelloWorld-Sample
About Chakkaradeep Chakkaradeep is the Microsoft Student Partner for University Of Otago. He writes two blogs: Chaks’ Corner and Chaks’ Geekzone Corner