< html > < head > < title > Display Date </ title > < script type ="text/javascript" src ="CreateSilverlight.js" ></ script > < script type ="text/javascript" src ="Silverlight.js" ></ script > <!-- Define Loaded event handler for TextBlock. --> < script type ="text/javascript" > function setDate(sender, eventArgs) { sender.text = Date(); } </ script > </ head > < body bgcolor ="Teal" > <!-- Define XAML content. --> < script type ="text/xaml" id ="xamlContent" > <? xml version="1.0" ?> < Canvas xmlns ="http://schemas.microsoft.com/client/2007" Background ="Wheat" > < TextBlock Canvas.Left ="20" FontSize ="24" Loaded ="setDate" /> </ Canvas > </ script > < div id ="pluginHost" > < script type ="text/javascript" > var parentElement = document.getElementById("pluginHost"); createSilverlightEx(); </ script > </ div > </ body > </ Html >
下面的JavaScript事例Show的是怎样在CreateSilverlight.js中的CreateSilverlightEx方法引用inline XAML内容,然后调用在Silverlight.js中 CreateObjectEx helper函数时.当你使用CreateObjectEx时候,参数值就不能使用默认的拉. function createSilverlightEx() { Silverlight.createObjectEx({ source: '#xamlContent', // Source property value, referencing an ID in the HTML DOM. parentElement:parentElement, // DOM reference to hosting DIV tag. id:'myPlugin', // Unique plug-in ID value. properties:{ // Plug-in properties. width:'360', // Width of rectangular region of plug-in, in pixels. height:'60', // Height of rectangular region of plug-in, in pixels. background:'oldlace', // Background color of plug-in. version:'1.0'}, // Plug-in version. events:{ onLoad:null}}); // OnLoad property value -- event handler function name.}
下面是图片是你结合上面的HTML和ilverlight plug-in 被加载后,TextBlock对相触发Loeded事件引起显示当前时间的Example. ---worksguo