Application and Programming Models
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Most Silverlight-based applications are written in managed code and make use of the Silverlight application model. However, you have the option of using a simplified programming model instead.
Silverlight provides the following two distinct models for application development:
The managed API for Silverlight, which uses code running on the common language runtime (CLR) for Silverlight. You can use the managed API with compiled languages such as Visual Basic and C# or dynamic languages such as IronPython and IronRuby. For more information about dynamic languages, see Silverlight Dynamic Languages SDK.
For more information about the functionality provided by the .NET Framework and the Silverlight presentation core, see Silverlight Architecture.
Managed Programming and the Application Model
The managed API enables you to bundle managed assemblies and resource files into application package (.xap) files. The Silverlight plug-in is responsible for loading an application package and extracting its contents.
An application package must contain an assembly with a class derived from Application. The Application class encapsulates the interaction between your application and the Silverlight plug-in. For example, it enables you to display a user interface within the host Web page. Additionally, it provides application lifetime events and resource management.
The Silverlight documentation uses the term application model to refer to application packaging and the common functionality encapsulated by the Application class. The application model helps you to develop both simple applications and complex, extensible applications that can share resources across a network.
For more information, see Application Model. The application model topics provide guidance on designing applications to enable several common scenarios, such as on-demand resource loading, download progress indication, and navigation.
The Managed API
When the Silverlight plug-in loads XAML files, it creates an object tree that your code-behind can manipulate. Your managed application code can also manipulate the HTML Document Object Model (DOM) through the HTML Bridge.
For information about how managed code interacts with XAML and HTML, see Managed API for Silverlight.
For more information, see Silverlight Programming Models, XAML, and the HTML DOM and HTML Bridge: Interaction Between HTML and Managed Code.
Using Multiple Silverlight Plug-ins in a Web Page
One reason to use the HTML Bridge feature is to create Web pages that integrate Silverlight with other HTML-based content. You can also use the HTML DOM to integrate multiple Silverlight-based applications in a single page. However, in this case, Silverlight provides built-in support for communicating between multiple Silverlight plug-ins, called local messaging.
Local messaging enables you to send messages from one Silverlight-based application to another one running on the same computer. This enables you to create Silverlight content that spans multiple plug-ins, such as an animation that crosses from a banner to a sidebar. For more information, see Communication Between Local Silverlight-Based Applications.
Using Silverlight Outside the Browser
Silverlight provides built-in support for running managed applications outside the browser. After you configure an application for out-of-browser support, users can install it from its host Web page. After installation, users can run the application without a browser or even a network connection. You can configure applications for out-of-browser support without modifying any application code. Alternately, you can implement additional support for out-of-browser mode, such as offline caching and automatic updates. For more information, see Out-of-Browser Support.
In Silverlight 4 and later, you can configure out-of-browser applications to require elevated trust. These trusted applications can bypass some of the restrictions of the Silverlight security sandbox and integrate with native functionality. In Silverlight 5 and later, system administrators can also enable trusted applications to run inside the browser. For more information, see Trusted Applications.
You can also use the Silverlight plug-in in other environments. However, in this case, there is no built-in support. The easiest way to integrate Silverlight with another technology is to host the Silverlight plug-in within a browser control. You can then host the browser control within the other technology. More complex hosting options involve the use of unmanaged code and COM interfaces. If you need the functionality of Silverlight in a desktop application, you should consider using Windows Presentation Foundation (WPF). For more information about using Silverlight in other environments, see Alternative Hosting.