Silverlight is primarily designed for hosting in a Web page. However, there are several alternative hosting options that enable Silverlight to run outside the browser or within another host environment.
Most alternative hosting options are outside the scope of the Silverlight documentation. However, this topic summarizes the options and provides links to additional information and sample code where available. In particular, the Silverlight Alternative Hosting page on the MSDN Code Gallery provides additional documentation and code samples for some advanced hosting options.
This topic contains the following sections:
Silverlight is subject to the same security sandbox restrictions regardless of the host environment or the presence of a Web browser. However, the host environment could provide full access to the local computer, effectively bypassing Silverlight security.
If a browser or network connection is not present, the host environment might have to provide replacement functionality depending on your requirements.
Silverlight provides basic out-of-browser support on Windows and Macintosh computers for your Web-hosted, Silverlight-based applications. This is the easiest way to use Silverlight outside a Web browser, but it requires that users install the application from a host Web page.
For more information, see Out-of-Browser Support.
For richer offline support, including full access to the local computer, consider using Windows Presentation Foundation (WPF). WPF provides a superset of Silverlight functionality and enables you to convert your Silverlight-based applications to full-featured Windows applications with minimal code modifications.
For more information, see Windows Presentation Foundation.
Using an embedded Web browser control is the easiest way to add Silverlight to an application that was created with another technology. In this case, your application hosts a browser control, which displays a Web page, which in turn hosts your Silverlight-based application.
Depending on your needs, you can hide the boundaries between the hosting layers and create a seamless user interface. To communicate between your host application and your Silverlight code, you can use the HTML DOM.
For information about how to access the HTML DOM from Silverlight, see HTML Bridge: Interaction Between HTML and Managed Code. To access the DOM from your host application, consult the documentation for your chosen browser control. The following list indicates some common browser controls.
Silverlight provides an unmanaged interface named ISilverlightViewer through which you can retrieve a bitmap rendering of a Silverlight-based user interface (UI). You can use this functionality to combine Silverlight UI elements with the UI of another application.
In this scenario, you typically embed the Silverlight plug-in behind the UI of the host plug-in or application. The host can then display specific parts of the Silverlight UI and receive any corresponding mouse and keyboard user input. Because the Silverlight UI can change in response to user input, the host will typically display rendering updates continually.
This hosting alternative is particularly useful for displaying Silverlight UI elements within another browser plug-in. In this case, the host plug-in can interact with Silverlight entirely through the ISilverlightViewer interface, while the browser handles the embedding details. Without the browser present, the host application must use another hosting option, possibly in addition to accessing the ISilverlightViewer interface.
The Silverlight Alternative Hosting page provides additional documentation for this hosting option, including sample code.
Silverlight provides several COM interfaces through which a Windows-based application can host the Silverlight plug-in. This approach provides significant flexibility, but also requires significant development effort.
With this option, your host application must provide the necessary COM hosting infrastructure, and must implement the IXcpControlHost and IXcpControlHost2 interfaces. You can then interact with the Silverlight plug-in through the IXcpControl and IXcpControl2 interfaces.
With Silverlight 4, you can host trusted applications and implement the IXcpControlHost3 interface to fulfill plug-in requests for Automation objects. For more information, see Trusted Applications and the COM Reference.
The Silverlight Alternative Hosting page provides additional documentation for this hosting option, including sample code. For more information about the Silverlight COM interfaces, see the COM Reference.
One final option is to host the Silverlight plug-in through the browser plug-in model. In this scenario, your host application assumes the role of the browser and embeds the Silverlight plug-in the same way a browser does.
This option provides relatively integrated access for Macintosh-based applications, where the COM interfaces are not available. In this case, you will typically use the NPAPI interface (also known as the Gecko Plugin API). For more information, see the Gecko Plugin API Reference.
This is an advanced hosting option for which there is currently no additional guidance.