Passing function references to the onPluginLoaded/onload event


hi,

i've got javascript needs know when silverlight object loaded , running. have tried <param name="onpluginloaded" value="myfunction">, not work, @ least not in beta 2. instead, <param name="onload" value="myfunction"> seems work.

however, requires myfunction function in global scope (window). writing code web page can contain several similar silverlight objects, created dynamically after page load. then, need event handler function in javascript class, , class instantiated in several objects.

ideally speaking, event handler should not public function either.

so, there way can pass function reference onload/onpluginloaded event in silverlight plugin?


thanks answer. not have been looking for, have found decent solution myself.

i assign javascript object property silverlight dom object in web page, , silverlight application, access object using htmlpage.plugin.getproperty method.

example:

javascript

function silverlightobjecthandler(elementid) {

  function callbackobj() {
     this.callbackmethod = function () { alert('callback silverlight')};
  }

  var newslelm = document.createelement('object');
  newslelm.setattribute('type','application/x-silverlight-2-b2');
  newslelm.setattribute('data','data:application/x-silverlight-2-b2,');

  (...)
  newslelm.callbackobj = new callbackobj();
  document.getelementbyid(elementid).appendchild(newelm);

}

page.xaml.cs

scriptobject callbacks = (scriptobject) htmlpage.plugin.getproperty("callbackobj");

callbacks.invoke("callbackmethod");

 

 



Silverlight  >  Programming Silverlight with JavaScript



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........