I am new to WPF. I am using "WebBroswer" in my wpf application to render a Google map. I have a googlemap.htm page and it contains a initialize(lat, log) JavaScript function. Now I want to call this function from my .xaml.cs file with lat and log parameters.
Googlemap.htm
<script>
function initialize(lat, log) {
var mapProp = {
center: new google.maps.LatLng(lat, log),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
The easiest approach is to use
WebBrowser.InvokeScript
method:Alternatively you could also rewrite you JavaScript code like this:
So now you can access
myfunc
from C# code:You could also invoke
myfunc
withoutdynamic
keyword: