I have a Silverlight application using C#, with 2 main functions that I want to make accessible from JavaScript functions. I have done the RegisterScriptableObject() in the class and set-up the [ScriptableMember] for the functions I want access to.
This the Silverlight object:
<div id='silverlightControlHost'> <object id='silverlightControl' data='data:application/x-silverlight,' type='application/x-silverlight-2' width='1024px' height='300px'> <param name='source' value='DrawingWaveForm.xap'/> <param name='onerror' value='onSilverlightError' /> <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> <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> </div>
and these are my JavaScript functions:
function Start() { var control = document.getElementById('silverlightControl'); control.Content.Page.Start(); } function Stop() { var control = document.getElementById('silverlightControl'); control.Content.Page.Stop(); }
Can anyone tell me where I’m going wrong as it does not seem to work
As timheuer said, [Scriptable] on your Silverlight methods.
Call this in your class:
Call the Silverlight methods marked as Scriptable from your javascript like this:
This page shows you this and how to do the reverse, calling javascript methods from Silverlight. It’s a really nice model.