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 开发者_如何学Gowould 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.)
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.
精彩评论