WPF Webbrowser with javascript use variable defined in c#? -
i trying pass array defined in wpf project in javascript function inside html page loaded in webbrowser control , don't find way that.
example of want :
xaml:
<webbrowser x:name="wbtimegraph" />
c#:
namespace graphnamespace { public partial class timegraph : window { // members public []int myarrayofdata = new int[50]; // methods public timegraph () { initializecomponent(); string dir = environment.currentdirectory; uri tnav = new uri(dir + string.format("/timegraph.html")); wbtimegraph.navigate(tnav); } } }
html :
<script> $(function () { // graph myarrayofdata }); </script>
the easiest solution found invoke javascript function paramaters update graph , pass serialised array parameter
html :
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script> <script type="text/javascript"> function updategraph(json) { var data = json.parse(json); // update graph new data // allow me use data serialised array - data[0] ... } </script>
c# :
added system.web.extension in référence script sérialisation
private void updatevalueinjavascriptgraph() { var serializer = new system.web.script.serialization.javascriptserializer(); var json = serializer.serialize(myarrayofdata); object result = this.wbtimegraph.invokescript("updategraph", new object[] { json }); }
Comments
Post a Comment