0

I'm writing a C# application using WebBrowser to render some webpages. In these webpages, there are .xap SilverLight plugins.

Now I want to capture the mouse and keyboard events on the Silverlight plugin, and handle them in the C# application.

I tried and It seems the Events taking places in Silverlight dosen't trigger WebBrowser's listener.

Is there any way about this? Thanks.

1 Answers1

0

You might be able to use the HTML Bridge

You will have to annotate the events you want to pass on from Silverlight to Html:

[ScriptableMemberAttribute]
public event EventHandler SomeEvent;

and then register an object that will be available in the Html of the page:

MyStockWatcher m = new MyStockWatcher();
HtmlPage.RegisterScriptableObject("stockwatcher", m);

stockwatcher will be available in javascript on the page.

Passing this on to the C# applications by using the answer to this question: How to detect javascript execution in WebBrowser control

Pass the event to C# by accessing window.external in the java script.

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115
  • Thanks. But the Silverlight app is compiled by others. I don't have its source code thus can't add any annotate onto it. Is there still any hope in this situation? – Xiaodi HU Oct 14 '14 at 07:40
  • At most you could detect global mouse events but you wouldn't have knowledge about what has been clicked on unless you add a lot of data/information to your application (locations of buttons, state, ....) – Emond Oct 14 '14 at 08:20
  • That could be a last resort. Thanks for your reply. – Xiaodi HU Oct 14 '14 at 08:40