This tutorial shows how to create a template to easily embed Silverlight controls on a page. Note, you must UNSAFECONTENT permission on your site to complete this tutorial.
First, we need to attach the silverlight control to a location where it can be accessed from. For example, I have attached the color picker control to this page. Just download it using this link and attach to a page on your own site.
Next, we need to create the HTML markup for embedding the sliverligth control. The easiest way to achieve this is to create template (e.g. Template:SilverlightEmbed). This will make it easy to reuse the template as needed. The following template is a little bit more sophisticated to make our lives even easier. It can either be used with an arbitrary URI (e.g. 'http://myserver/folder/ColorPicker.xap') or simply with the name of a Silverlight control that is attached to the current page (e.g. 'ColorPicker.xap').
/***
USAGE:
SilverligthtEmbed(source, width, height)
Embed a Silverlight control on a page.
PARAMETERS:
source : str
Source URI where the Silverlight.xap file is located. If uri is not a valid URI, it is assumed to be the name of
a file attachment on the current page.
(optional) width : num (default: 450)
Width in pixel or percent for the Silverlight control.
(optional) height : num (default: 400)
Height in pixel or percent for the Silverlight control.
***/
// check if uri parameter points to a
var source = $0 ?? $source;
if(!uri.isvalid(uri)) {
let source = page.files[source].uri;
}
// embed silverlight code
<object data="data:application/x-silverlight," type="application/x-silverlight-2" width=($1 ?? $width ?? 550) height=($2 ?? $height ?? 400) >
<param name="source" value=(source) />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
To install this template on your site, follow these steps:
Now, we're ready to embed our silverlight control on the page. This task is trivial thanks to the template we created in step 2. Edit the page where you added the Silverlight control to. Put the cursor on an empty line and select the DekiScript style from the dropdown menu. Enter the following code (adjust the name of the control if needed) and save the page.
SilverlightEmbed('ColorPicker.xap')
Here is what you should be seeing.
Embedding Silverlight controls is easy to do, but creating a template makes it even easier. There is a myriad of uses for the template and it is a great starting point to build on. Hope you found it useful and let us know what you've built!
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by