c# - Run notepad.exe from a html-button using Awesomium -
i've been looking example on how open process notepad.exe html-element using wpf , awesomium 1.7.5. idea clicking html element triggers c# method using javascript far understand awesomium api. however, examples can find refer earlier version uses obsolete functions...
can please provide me example on how execute c#-code when opennotepad() triggered?
html:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <button onclick="app.opennotepad()">this button open notepad</button> </body> </html>
c#:
public partial class mainwindow : window { public mainwindow() { initializecomponent(); webcontrol.source = new uri("index.html"); } private void webcontrol_documentready(object sender, documentreadyeventargs e) { bindmethods(webcontrol); } private void bindmethods(iwebview _webview) { jsvalue result = webcontrol.createglobaljavascriptobject("app"); if (result.isobject) { jsobject appobject = result; appobject.bind("opennotepad", opennotepad); } } private jsvalue opennotepad(object obj, javascriptmethodeventargs jsmethodargs) { process.start("notepad.exe"); return null; } }
xaml:
<window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:awe="http://schemas.awesomium.com/winfx" x:class="omega.mainwindow" title="omega" height="350" width="525" windowstartuplocation="centerscreen" windowstate="maximized" resizemode="noresize" topmost="true" windowstyle="none"> <grid> <awe:webcontrol x:name="webcontrol" documentready="webcontrol_documentready" /> </grid> </window>
according awesomium documentation bind , javascriptmethodhandler, methods of handling javascript events has changed in version 1.7.5.
javascriptmethodeventhandler obsolete, , new bind overload should used.
now code
private void bindmethods(iwebview _webview) { jsvalue result = webcontrol.createglobaljavascriptobject("app"); if (result.isobject) { jsobject appobject = result; appobject.bind("opennotepad", opennotepad); } } private jsvalue opennotepad(object obj, javascriptmethodeventargs jsmethodargs) { process.start("notepad.exe"); return null; }
note, there example of using new overload @ end of bind documentation page.
also note javascript method in sample not calling app.opennotepad()
method, alert("run notepad");
Comments
Post a Comment