Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes calling a ScriptableMember method on a Silverlight control from JavaScript create a new Instance of the control?
    text
    copied!<p>I have a Silverlight control with a method named <code>DoSomething()</code> decorated with the <code>&lt;ScriptableMember()&gt;</code> attribute. I then call this method <em>successfully</em> from JavaScript and proved by a little message box that apprears from the SL side that says "Method Called!".</p> <p>Point is all that works. The problem I am having is that <em>prior</em> to calling this method I build up an ObservableCollection on the Silverlight control containing 1..n <code>FileInfo</code> objects. This works fine too and builds up as I add files to it. Each time I add a file, a messagebox tells me the count from Silverlight (i.e. "Count = 2").</p> <p>Now the problem: when I call the method <code>DoSomething()</code> from JS and access that ObservableCollection the count = 0! To see what is going on I placed a message in the Silverlight control's constructor to see if it gets entered upon being called from JS, and indeed <em>it does</em> and appears to recreate the control.</p> <p>If this is the case it kind of makes sense that my ObservableCollection has a count = 0 because it is not the same control instance where I built up the FileInfo collection.</p> <p>So how in the world do I preserve the collection, and why would simply calling a method exposed to JS from Silverlight, recreate the control and not allow me to access it's given state? I don't want a new control, I need to manipulate it as-is. Or am I off base and doing something else wrong to cause this beahvior?</p> <p>Thoughts? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload