Application class in Silverlight
This document correspondsSilverlight 2"Application Model"Chapter, Microsoft's introduction sequence may focus on the macro architecture, and this article belongsProblem-oriented. In practiceInitialization page,Load otherXapApplication inProgram,Call resource filesIn the process of solving the problem, I read this part continuously. Although the problem is solved one by one, it is more profound to reorganize and sort out your own ideas.
ApplicationClass encapsulatesSilverlightApplication (Singleton mode), which mainly represents the applicationCodeInSilverlightEntry point in the plug-in Life Cycle (refer to the plug-in activation process ). Provides several services: application lifetime management,
Application resource file loading,
Unhandled exception handling andWebHost Integration. ("Application Service")
application the class has three event members: startup , exit and unhandledexception . When you create a Silverlight application, in the automatically generated app. XAML. CS the corresponding event processing method is displayed. exit and unhandledexeption you can view the help documentation. For now, only startup event.
StartupIt is used to perform initialization operations when the application is started.RootvisualProperty to display the home page. The second is to retrieve the passed parameters. Startupeventargs
Object
Initparams
Properties, for example, how to determine different start pages, referTerryleeIn Silverlight 2Switching user controls in applications . You can also useHtmldocument. querystringSearch from the host webpageURLParameter, throughIsolatedstoragesettingsClass to retrieve session data of previous applications.
In addition, Startup Other resources can also be retrieved, such Webclinet Asynchronous download of other resource files or assembly. If the file is Zip Or Xap , You must use Application.Getresourcestream Method. If the file is an assembly, create a new Assemblypart Object, and call its Load Method. Of course, you do not need to call other resource files. Startup . For example, you can click a button on a page to trigger the event and call other Xap .
Understand external call Xap In the assembly process, first you need to understand" Application Structure ", View and understand Appmanifest. XAML File. Note that, Beta2 China site Deployment Object To obtain Appmanifest. XAML The element in the file is no longer valid and can be used LINQ Read. See 《 Dynamic Load & invoke other xap for Silverlight 2.0 ", The content is Chinese. This articleArticleThere are improvements. For example, this process is abstracted as a method for future direct calls.
ApplicationClass ProcessingApplication. getresourcestreamAnother common method isApplication. loadcomponent. ViewPagePage ConstructorInitializecomponent ()Method to see its appearance. This method is also commonly used to call"Build action"Is"Page"XAMLFile, refer to Dynamic Loading XAMLFile .
ApplicationThere are other methods, which will not be described one by one. Finally, let's take a look.Application,Current,Host,ResourceAndRootvisual.
Application. CurrentUsed to provideApplicationShared access to the instance. Generally, the system automatically generatesApplictionInheritedAppClass, so the common form is:APP currentapp = (APP) application. Current;
Host.SilverlightDetailed information about the host of the application. For exampleTxtblock. Text = app. Current. Host. background;
Application. ResourceIt often appears inApp. XAMLFile refers to the resources applied to the entire application. Resources in a single page domain andInlineType resource.
RootvisualTo obtain or specify the start page of the application.
applicaitonde app class, custom implementation of an inherited from application class, omitted. end >