Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Silverlight Invoke Javascript function in a namespace?

I'm having a problem since I wrapped my javascript functions inside of a namespace. Version 1 of my code worked fine. Originally, to call the javascript from inside Silverlight I used to use this code:

HtmlPage.Window.Invoke("hideMyDiv");

My javascript looked like this:

function hideMyDiv() {
$('#MyDiv').fadeOut();

}

Now, I've refactored my javascript to be contained in a namespace. So it now looks like this:

var activity = {
message: null,
hideMyDiv: function() {
    $('#MyDiv').fadeOut();
}   };

I can call this refactored function in javascript, it works like before:

$("document").ready(function() {
activity.hideMyDiv();   });

But when I try to use it from Silverlight, I get this error: Failed to Invoke: activity.updateInfo. This is my current Silverlight code:

HtmlPage.Window.Invoke("activity.hideMyDiv");

What am I doing wrong? (and thanks!)

like image 518
bperreault Avatar asked Aug 12 '09 19:08

bperreault


1 Answers

This is the correct way..

ScriptObject so = HtmlPage.Window.Eval("activity") as ScriptObject;
so.Invoke("hideMyDiv");
like image 160
Akash Kava Avatar answered Oct 21 '22 00:10

Akash Kava