Overview
The XAP file is a file compiled and packaged by the Silverlight 2 application. It is a standard zip compressed file that includes all the files required by the Silverlight 2 Application, such as assembly and resource files.
This section describes the XAP files in Silverlight in detail.
What is an XAP file?
The XAP file is a file compiled and packaged by the Silverlight 2 application, including all files required by the Silverlight 2 application, such as assembly and resource files. Here, xap does not have any special significance. It is only the extension of the file generated after the Silverlight 2 application is compiled. In essence, xap is a standard zip compressed file. You can modify the. xapfile extension to the. ZIP file and use the decompression tool to open the file. You can see the file contained in the file:
How to Use XAP files
We are familiar with the use of xap files. On the ASP. NET page, we can use Silverlight Control to reference xap files, as shown in the following code:
Note that the Silverlight control depends on ScriptManager. Therefore, you must have a ScriptManager control on the ASP. NET page. In HTML pages (or PHP, JSP, etc.), we can use the following method:
The type = "application/x-silverlight-2-b2" Here specifies the current version of Silverlight 2 Beta 2, followed by a hyperlink that specifies the image shown when the Silverlight 2 plug-in is not installed on the user's machine.
How to execute XAP files
Once an xap file is referenced, The Silverlight plug-in downloads the xap file and runs it in an independent sub-window when the application is running, as shown in:
What does XAP file contain?
At the beginning of this article, we will say that the XAP file contains all the files required by the Silverlight 2 application, such as the Assembly and resource files, but it will contain at least two files, one is the assembly of the current Silverlight application, and the other is AppManifest. xaml file. The AppManifest. xaml file is equivalent to a list (similar to an inventory ticket), as shown in the following code:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="XapFileExplain" EntryPointType="XapFileExplain.App" RuntimeVersion="2.0.30523.6"> <Deployment.Parts> <AssemblyPart x:Name="XapFileExplain" Source="XapFileExplain.dll" /> </Deployment.Parts></Deployment>
It includes at least the following information:
1. Application Entry Point Assembly
2. Types of application entry points
3. version when the application is running
4. All application-related Assembly
How to generate XAP files
XAP files are automatically generated by the development environment during Silverlight project compilation. Generally, manual control is not required. Here you may think of a problem. If too many assembly files are packaged in the XAP file, the file size will increase. Although some assembly is used in the program, however, it is not necessary to download the XAP file. It may be used at a specific time. In this way, you can not just package some necessary assembly, what about other downloads when needed? Naturally, the answer is yes.
For example, the System. Windows. Controls. Extended Assembly is used in our program, but we don't want it to be packaged in the xap file. What should we do? You can set the Assembly attributes, as shown in:
We can set the Copy Local attribute of the assembly to False so that the Assembly will not be packaged in the XAP file. When necessary, we can download the Assembly manually, such as using WebClient for download.
Summary
This topic describes the XAP file in Silverlight 2 in detail and hopes to be useful to you.
For more information about Silverlight 2, see Silverlight 2.