locked
Save silverlight app as picture RRS feed

Answers

  • You can use javascript to invoke a method inside your Silverlight application that will use WriteableBitmap to capture the application as an image.

    Tuesday, April 19, 2011 9:24 AM

All replies

  • You can use javascript to invoke a method inside your Silverlight application that will use WriteableBitmap to capture the application as an image.

    Tuesday, April 19, 2011 9:24 AM
  • How would you go about doing that?

    Tuesday, April 19, 2011 9:42 AM
  • I'm not really getting this to work.

    This is what i have, and it looks like it doesn't call anything in my silverlight app..

    There is no alert comming up..

    What am i doign wrong?

    My javascript function:

        <script type="text/javascript">
            function SaveSignature() {
                var Plugin = document.getElementById("SilverlightControl");
                var strOut = Plugin.Content.SignatureApp.SimpleMethodExample("lala");
                alert(strOut);
            }
        </script> 



    My silverlight object:

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"
                             id="SilverlightControl">
    ...
    </object>



    My silverlight test method:

            public MainPage()
            {
                InitializeComponent();
    
                // Create and register a scriptable object.
                HtmlPage.RegisterScriptableObject("SignatureApp", this);   
            }
    
            [ScriptableMember]
            public string SimpleMethodExample(string s)
            {
                HtmlPage.Window.Alert("You called the Silverlight 'SimpleMethodExample'\n" +
                    "and passed this string parameter:\n\n" + s);
                return "Returned from managed code: " + s;
            }


    Heeeeelp me :(

    Tuesday, April 19, 2011 10:26 AM
  • I have created a sample on HTML integration. You can get it from my dropbox:

    http://dl.dropbox.com/u/4243120/HtmlIntegration.zip

    Tuesday, April 19, 2011 11:12 AM
  • Your example seems to work fine, but I honestly can't see any difference in yours and mine, except for the fact, that you create a new class, for your scriptableobject, where I just register 'this'.

    Even if I try to create a new class for the method, it doesn't work.

    Wednesday, April 20, 2011 2:18 AM
  • I cannot seem to figure out what is wrong. Can i somehow debug, and see what it does? To me, it looks like it doesn't find the method in the silverlight app.

    I've added some alerts to my javascript, and the last one i see is "Got plugin".


        <script type="text/javascript">
            function SaveSignature() {
                alert("In javascript");
                var Plugin = document.getElementById('slControl');
                alert("Got plugin: " + Plugin);
                var strOut = Plugin.Content.SignatureApp.SimpleMethodExample('lala');
                alert("Did method call");
                alert(strOut);
                alert("Leaving javascript");
            }
        </script> 


    Wednesday, April 20, 2011 4:02 AM
  • Actually, it seems like it is working in IE but not in Chrome.

    Wednesday, April 20, 2011 5:09 AM