locked
Call Silverlight from javascript? RRS feed

  • Question

  •  I am new to silverlight , I want to know if I can call all the  silverlight functionality from Javascript ?I hope that one expert can give me a good sample or good resources?

     

    Thanks.

    Wednesday, February 3, 2010 9:15 AM

Answers

All replies

  • There was a previous question on the forums that discussed this, here is the article

     http://forums.silverlight.net/forums/t/19253.aspx

     and this is the article that will help you.

     

    http://msdn.microsoft.com/en-us/library/cc221414(VS.95).aspx

    Wednesday, February 3, 2010 9:56 AM
  • Hi

    In Silverligth 

    [ScriptableMember]
    public string Save()
    {
    }
    in Appxaml.cs
    private void Application_Startup(object sender, StartupEventArgs e)
            {
                MainPage p = new MainPage(e.InitParams);
                HtmlPage.RegisterScriptableObject("mySLapp", p);
    
                this.RootVisual = p;
            }
    
     
    
     The sl object tag in your html 
    
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    		  <param name="source"  value="components/com_xmlspielplan/ClientBin/XMLTableEditor.xap"/> 
    		  <param name="initparams"  value="Tabelle=<?php echo $this->auto->fulpath ?>" /> 
    		  <param name="onError" value="onSilverlightError" />
    		  <param name="onLoad" value="pluginLoaded" />
    		  <param name="background" value="white" />
    		  <param name="minRuntimeVersion" value="3.0.40624.0" />
    		  <param name="autoUpgrade"  value="true" />
    		  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" mce_href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
     			  <img src="http://go.microsoft.com/fwlink/?LinkId=108181" mce_src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
    		  </a>
    	    </object>

     the java script

     var slCtl=null;
        
    function pluginLoaded(sender,args){      // HTML version 
           slCtl = sender.getHost(); 
    	  
    }

    After this you can call  

    slCtl.Content.mySLapp.Save()
    

     

    see also http://msdn.microsoft.com/en-us/library/cc221414(VS.95).aspx 

    Wednesday, February 3, 2010 10:39 AM