I have had not trouble passing primitive values from Javascript to Silverlight through the HTML bridge, but I keep getting stuck when trying to pass a Dictionary. Furthermore, I can't find a single sample of this working anywhere online, though the MSDN documentation says it should just happen automatically. Instead, I get an error that the type cannot be converted to a Dictionary.
Here's the javascript code:
mapPlugin = null;
function pluginLoaded(sender) {
var mapPluginObject = $find("<%=silver.ClientID%>");
mapPlugin = mapPluginObject.get_element();
}
function Proxy() {
var dict = {};
dict['Color'] = 2;
dict['Foo'] = 'Bar';
slPlugin.Content.DataSeriesManager.Scriptable(dict);
}
...
<asp:Silverlight ID="silver" runat="server" Source="~/ClientBin/silver.xap"
MinimumVersion="2.0.31005.0" OnPluginLoaded="pluginLoaded" Width="100%" Height="100%" />
Then on the C# / Silverlight side, I have:
private void Application_Startup(object sender, StartupEventArgs e)
{
Page page = new Page();
HtmlPage.RegisterScriptableObject("DataSeriesManager", page.DataSeriesManager);
this.RootVisual = page;
}
[ScriptableType]
public class DataSeriesManager
{
[ScriptableMember]
public void Scriptable(Dictionary<string, object> dict)
{
// ...
}
}
Thanks,
-Scott