Developing for Silverlight using Javascript - is this possible? -
my tech lead told me possible develop silverlight apps solely javascript. did googling , binging; likes primary development method developing pre silverlight 2.0. seems have lost favor c# of sl 2.0.
is still possible develop silverlight apps solely javascript? know silverlight , browser have extensive scripting capabilities , can scripted via js; can build sl app it?
it still possible, though experience different. must load initial root visual element via source property on silverlight object referencing xaml file on server, after have full access visual tree via javascript.
the below test.html , root.xaml files produce testable page if placed in same folder.
note differences "standard" (i.e. *.xap source) scenario - 'source' parameter on sl object tag set .xaml file instead of .xap file. .xaml file different in default sl application in vs: x:class="myapp.mainpage" missing root element, , root element grid (or visual element) instead of usercontrol element. because there no application (at least not loaded .xap - assume sl control creates default application instance in process of loading root.xaml file), , no usercontrol because there no code-behind. consistent pre-sl1.1/2.0 experience of no usercontrols.
additionally, need reference javascript api silverlight reference in javascript coding. have fun findname method and/or walking visual tree! ways references visual objects manipulate code!
test.html
<html> <body> <object id="slobject" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400" height="300"> <param name="source" value="root.xaml"/> <param name="onerror" value="onsilverlighterror" /> <param name="background" value="white" /> <param name="minruntimeversion" value="4.0.50826.0" /> <param name="autoupgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?linkid=149156&v=4.0.50826.0" style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?linkid=161376" alt="get microsoft silverlight" style="border-style:none"/> </a> </object> <input type="button" onclick="saygoodbye();" value="say goodbye, silverlight!" /> <script> function saygoodbye() { var slobject = document.getelementbyid('slobject'); var slcontent = slobject.content; var layoutroot = slcontent.findname('layoutroot'); var message = layoutroot.findname('message'); message.text = 'goodbye'; } </script> </body> </html>
root.xaml
<grid x:name="layoutroot" background="white" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d" d:designheight="300" d:designwidth="400"> <textblock x:name="message" text="hello, silverlight!" fontsize="30" horizontalalignment="center" verticalalignment="center" /> </grid>
Comments
Post a Comment