Silverlight Browser Integration - Microsoft Silverlight

What is Silverlight Browser Integration?

In this section, we are going to understand how a Silverlight application can work in union with a web page using the browser integration support.
We can walk around Silverlight integration with the browser in the next two ways −

  • JavaScript code running in the browser can access features within your Silverlight application.
  • Silverlight has the skill to deliver JavaScript wrappers for objects. Your .NET code running inside the Silverlight plug-in has access to the HTML DOM and other browser scripting features because of Silverlight .NET wrappers for JavaScript objects.

We will see how a browser based software application can store information determinedly on the client.

Silverlight and HTML

Silverlight content is just a single element, as far as the world of HTML is concerned. This is true for layout. The entire of the Silverlight plug-in and all its content looks like just a single object element.

You need keep in mind that −

  • Silverlight was not a spare for HTML; it was designed to complement it. So, the capability to access just another element in the DOM is important.
  • It allows you to use Silverlight where appropriate.
  • On a page, that mostly uses HTML, Silverlight integration with the world of the browser goes beyond merely existing as a DOM element, subject to normal HTML Layout.

Accessing DOM

The Silverlight content need able to participate fully in a web page. Therefore, it must be able to access the HTML DOM. Silverlight offers the bridge objects that wrap browser script objects as Dot Net objects, the Script object class in the system. The browser namespace affords methods that let you read and write properties and devote functions on the browser script object.

You need a way to get hold of a Script object in the first place. Silverlight provides an HTML page class that gives you access to various pages of the features such as the Script objects.

Let us have a look at a simple instance in which we have a simple script that creates an object with a few attributes. Some of them are just values and a couple of them are functions.

Given below is the XAML code in which a button is added.

Here is the button click implementation in which a script is called which is created in HTML file.

Given below is the complete HTML file.

When the above code is compiled and executed, you will see all the values in the output window, which are fetched from the HTML file.
accessing_dom

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Microsoft Silverlight Topics