Intersoft ClientUI 8 > ClientUI Fundamentals > Application Framework Overview > Application Framework How-to Topics > How-to: Create and Load an Instance of ApplicationPackage |
This example shows how to create an object instance of the main type associated to an ApplicationPackage, and then add the object to the visual tree.
Once an ApplicationPackage has been downloaded, you can create an instance of object which type is specified in the MainType property. The main type and possibly other properties are automatically parsed from the XML application metadata (SAFMetadata.xml) of the particular application, with note that EnableMetadataDiscovery is set to True while performing the download. For more information how to download an ApplicationPackage using API, see How-to: Download an External ApplicationPackage.
The type used as the main type of an application package should be a type that can be injected as a visual child in the Silverlight and WPF visual tree, which commonly derives from FrameworkElement class. |
The following example shows how to get the application using GetApplication method, and then load the application into the current domain context using the Load method, and finally create an instance of the application using CreateInstance method which result is assigned to the Child property of a Border.
C# |
Copy Code
|
---|---|
ApplicationPackage app = UXShell.Current.GetApplication("ExternalClientUIApp1"); if (app != null) { // load the application to the current domain context app.Load(); if (app.IsLoaded) { FrameworkElement element = app.CreateInstance() as FrameworkElement; if (element == null) throw new Exception("Unsupported instance type"); Container.Child = element; } } |
The above example presumes that a ExternalClientUIApp1.xap file existed in the ClientBin of the Web project, which should be the same folder where the root application existed.
To create a new ClientUI Application, you use the ClientUI project templates installed in Visual Studio 2010. For more information, see Introduction to ClientUI Project Templates.