I am looking for a way to trigger a custom event in javascript from C# code written in a Windows Runtime Component with the AllowForWeb
Attribute.
I know that the other way around works (triggering an event from javascript to C#) like this
public delegate void NotifyAppHandler( string str );
[AllowForWeb]
public sealed class WebViewInjectionObject
{
public event NotifyAppHandler OnNotifyApp;
public void NotifyApp( string str )
{
OnNotifyApp?.Invoke( str );
}
}
You can then subscribe to the event in C# and trigger it from javascript like this
nativeObject.notifyApp(JSON.stringify(callInfo));
Where nativeObject
has been injected into the WebView
with AddWebAllowedObject
Now I am looking for a solution to do the opposite.
I want to create an event in javascript and trigger it from C# using again the injected object from the Windows Runtime Component.
You can assume that I have control over the javascript code that will run in the WebView
and can make changes there if required.
Note: The need to do this quite unorthodox thing arises from the fact that I cannot use/don't want to use InvokeScriptAsync
due to this issue