I am making a WPF application use WebView2.
There will be an installer that will installer the WPF application in a folder and will also download and write the website into a subfolder of the installation directory. Such as this:
Installation Directory
├───Website
│ ├───index.css
│ └───index.html
└───WPF Self Contained EXE
The WebView2 will load the website using this (I think): webView.CoreWebView2.Navigate(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Website");
This should load index.html
and all the files it references such as index.css
.
Now my main concern is that how do I call a JavaScript function from C#. So far after googling I have only found ways for WebView1. And I couldn't find anything about calling a C# method from JavaScript.
So three things:
- Is this
webView.CoreWebView2.Navigate(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Website");
correct for loading a website from a local folder? - How would I call a JavaScript function and pass an C# object to it from a C# method.
- How would I call a C# function from the JavaScript script?
Is this even possible?
Thanks.