I just wanted to try out what is the smallest Silverlight application without all the files that VS creates.
- I created a new project in VS (Chose “Generate HTML Test Page to host Silverlight…” option)
- Deleted following files
- AssemblyInfo.cs from Properties
- Only references I kept were (mscolib, System and System.Windows)
- Deleted App.xaml (& App.xaml.cs) as well as Page.xaml (& Page.xaml.cs)
- Created a new class named App (I kept the same name as what VS created, otherwise you will have to go into properties and change “Startup Object” drop down box from Silverlight Tab.
- this class had following code
XAP that was created was 2449 Bytes.
Now lets see how this works..
To peek inside XAP file, I just renamed the XAP file to ZIP file.
It had two things…
One of the first thing to notice is that manifest (it is list of things that describes the application) is in XAML format and it looks like below.
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="SilverlightApplication2" EntryPointType="SilverlightApplication2.App" RuntimeVersion="2.0.30226.2"> <Deployment.Parts> <AssemblyPart x:Name="SilverlightApplication2" Source="SilverlightApplication2.dll" /> </Deployment.Parts> </Deployment>
- Root tag (Deployment) has following pieces of interesting information
- EntrypointAssembly: Tells the silverlight app activation code which assembly is the entrypoint for the assembly. This assembly is required to be in XAP
- EntrypointType: This is the name of the application class that will be instantiated as part of the activation of an app
- RuntimeVersion: version of silverlight this application was built against.
- Deployment as collection of parts. These parts are pieces of application
- My simple app only has one assembly so it has one AssemblyPart which points to SilverlightApplication2.dll.
- When activation code instantiates the application class, constructor in my code hooks up the startup event for an application
- when application is ready to execute, Startup event is fired. In the simple app code above, the only things I do…
- Create a new TextBlock
- Set a Text property of that textblock to be “Hello TextBlock”
- Set a layout container (Canvas) as the root visual of the application
- Add newly created Textblock on that canvas.
here is the project.