Saturday, December 18, 2010

JavaScript and SilverLight

I was trying out some SilverLight usig the project Template from VS Web developer and I wanted to to spawn a simple alert .
To register JavaScript from MailPage.xaml.cs, you need to HtmlPage.RegisterScriptableObject("Page", this);
and use the HtmlPage.Window.Invoke("<jsfunctionname>","<parameter>")

and from JavaScript in Silerlightap...aspx add a function with a simple alert mesaage, a parameter can be used as well
 in xaml:
<Grid x:Name="LayoutRoot" Background="White">
        <TextBlock x:Name="text">text</TextBlock>
If you have a TextBlock in xaml then that textblock can be accessed from the cs and by using the attribute
[ScriptableMember]   you can write a function to modify some text value the cs, and since its ScriptableMember the value can be passes from JavaScript.

I think the syntax in JavaScriot would be something like
document.getElementById('silverlightControl'); //get the control having a textbox
page.<cs function>(some value);
and this would have the value in the silverlight control

I had read somewhere about this and I cannot find it now, I will do a test ASAP

No comments:

Post a Comment