I forget to put [Scriptable] in my EventArgs class. You can try the code below. I hope it works.
The new EventArgs class with parameters
[Scriptable]
public class EventArgs<T> : EventArgs{
private T _data;
public EventArgs(T args)
{
_data = args;
}
public T Data
{
get
{
return _data;
}
}
}
Page.xaml.cs
[Scriptable]
public partial class Page : Canvas {
public Page() {
WebApplication.Current.RegisterScriptableObject("EntryPoint", this);
MouseLeftButtonDown += Page_MouseLeftButtonDown;
}
void Page_MouseLeftButtonDown(object sender, MouseEventArgs e) {
if (CallbackToBrowser != null) {
CallbackToBrowser(this, new EventArgs<string>("my value"));
}
}
[Scriptable]
public event EventHandler CallbackToBrowser;
}
TestPage.html.js
// JScript source code
//contains calls to silverlight.js, example below loads Page.xaml
function createSilverlight()
{
Silverlight.createObjectEx({
source: "Page.xaml",
parentElement: document.getElementById("SilverlightControlHost"),
id: "SilverlightControl",
properties: {
width: "100%",
height: "100%",
version: "1.1",
enableHtmlAccess: "true"
},
events: {
onLoad: OnLoaded }
});
// Give the keyboard focus to the Silverlight control by default
document.body.onload = function() {
var silverlightControl = document.getElementById('SilverlightControl');
if (silverlightControl)
silverlightControl.focus();
}
}
function OnLoaded(sender, args)
{
sender.Content.EntryPoint.CallbackToBrowser = onManagedCallback;
}
function onManagedCallback(sender, args)
{
if(args.Data){
alert(args.Data);
} }
(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)
Best Regards,
Michael Sync
Blog : http://michaelsync.net
Feed : http://michaelsync.net/feed