Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does JavaScript hook WinRT events?

Suppose I'm writing a WinRT app with both JavaScript and C# code, and I want my JavaScript code to hook an event on my C# object.

I know that's supposed to be possible, but what would that JavaScript code look like? How are events (however the concept of a CLR event is represented in WinRT) exposed in the JavaScript projection?

If a concrete example would help, let's say my C# object has this event:

public event EventHandler Initialized;

How do I hook that event from JavaScript?

(I'm sure the answer is buried in one of the //build/ videos, but they're not exactly searchable.)

like image 667
Joe White Avatar asked Oct 03 '11 00:10

Joe White


1 Answers

Once you have your C# class hooked up and accessible from JavaScript (see C# //Build/ talk for details), it should be as simple as this:

var foo = new CSharpClass();
foo.addEventListener("Initialized", onInitialized);

Then when C# fires the event, your onInitialized function will be called.

like image 77
Steve Rowe Avatar answered Sep 21 '22 14:09

Steve Rowe