The default Silverlight project template creates a file called "App.xaml". What is this file used for?
There are a couple different uses for this file. Essentially it is a derived class of Application.
-
Global Resource declarations - Using the Application.Resources property you can define application level resources. Such as styles, data templates and
control templates.
-
Startup, Exit, and Error Handling Events (code-behind) - The code-behind of this file is used to handle application level events such as Startup, Exit and UnhandledException.
-
Application.Current Reference (code-behind) - This application is accessible via the global static variable Application.Current. You can cast this anywhere in your application.
-
Assigning RootVisual (code-behind) - The RootVisual is used to setup the startup Silverlight UserControl. This property needs to be set in the Startup event.
-
Install the application Out-Of-Browser (code-behind) - Using the Install method you can prompt the user to install the application Out-of-Browser.
-
Check for Application Updates (code-behind) - The CheckAndDownloadUpdateAsync method is used when the application is running out-of-browser to ensure that the .xap file is the latest.
xaml stand for extensible application markup language. This is just an XML file that allows you to declare the UI for Silverlight and even .Net objects
app.xaml allows you to declare resources that are shared across the application. Also the app.xaml.cs contains the application level events:
- Application_Startup
- Application_Exit
- Application_UnhandledException