Managed API for Silverlight
Microsoft Silverlight will reach end of support after October 2021. Learn more.
The Silverlight API defines its set of objects as object trees that enable you to populate the initial content of a Silverlight-based application by loading XAML, and then adjust the object tree at run time. In the managed API, interaction with the Silverlight object tree is defined with managed code. Using the CLR, your managed code is compiled into an assembly. The assembly typically also contains the XAML for your Silverlight-based application. Your managed code can support the Silverlight application model, and can be called in response to object lifetime events or user-initiated events. You might also use managed code to write support classes, to define data objects, and for many other application scenarios. You can also use the DLR rather than the CLR, which is discussed in Dynamic Languages in Silverlight.
Characteristics of the Managed API
Managed Code Is Extensible
Managed Code-Behind and Partial Classes
The primary technique for defining a UI in Silverlight is to define the elements in XAML markup. This might include use of styles and templates, which are also defined in XAML markup. In many cases you will want to factor the markup into different XAML files that integrate with the Silverlight application model. In order to define the interaction that is needed for the application, you generally want to define event handlers that respond to object lifetime events or user-initiated events for the objects defined in XAML. In the managed API, each XAML page where event handling is required, or where the XAML is intended as root element content, must undergo a markup compile pass as part of the build. The markup compile pass provides the necessary hookups for run-time interaction with the object tree that is created when the XAML page is loaded. These hookups include the event handlers as well as references for any object that is given a Name or x:Name in the XAML. In the Silverlight architecture, XAML is not compiled in its entirety. Much of the object tree creation that comes from XAML markup for UI is deferred until the XAML page is actually loaded into an application at run time and is processed by the Silverlight XAML parser. These concepts are explained in more detail in Code-Behind and Partial Classes.
Formalized DOM Interaction
APIs that expose the commonly used parts of the DOM (for instance, the Document object) to managed code.
Facilities that can make your managed types scriptable from the DOM.
APIs that specifically expose the Silverlight plug-in's object representation in the DOM.
For more information, see HTML Bridge: Interaction Between HTML and Managed Code or Silverlight Programming Models, XAML, and the HTML DOM.