How do you pass a List object to Javascript in Silverlight?
I have a silverlight class with the following block of code:
List<string> s = new List<string>();
s = command.DDECommand; //command is an object that i pass to this static class and DDECommand is a L开发者_JAVA百科ist<string> within that object.
if (HtmlPage.BrowserInformation.Name == "Microsoft Internet Explorer")
{
(Application.Current.RootVisual as FrameworkElement).Dispatcher.BeginInvoke(delegate()
{
HtmlPage.Window.Invoke("javascript_cmd", s);
});
return true;
}
I've read here that you should be able to pass a List of strings to a javascript function and be able to iterate through the list in javascript. However when I try to do the this, as illustrated in the above code, I find that javascript only receives the parameter as the string "{...}"
. Was this post incorrect? Is there anything I am doing wrong in passing the List?
I think you are missing this:
One thing to remember, when returning objects from a Silverlight method call to JavaScript, is they need to be marked as Scriptble using the ScriptableType attribute
This article here should help
精彩评论