I am trying to change the CSS of a loaded Website in a WebView (not local) by injecting a Javascript Function. I found these two Articles (Article 1, Article 2) but after implementing both Versions I always get the following Exception: System.NotImplementedException {"The method or operation is not implemented."}
This is my Code so far:
MainPage.xml
...
<WebView x:Name="WebView" LoadCompleted="webViewCSS_LoadCompleted"/>
...
MainPage.xaml.cs
...
private void webViewCSS_LoadCompleted (object sender, NavigationEventArgs e)
{
addCss();
}
private void addCss()
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("function setCSS() { ");
sb.Append("document.getElementsByClassName('app')[0].style.width = '100%';");
sb.Append("} ");
string script = sb.ToString();
WebView.InvokeScript("eval", new string[] { script });
WebView.InvokeScript("eval", new string[] { "setCSS()" });
} catch (Exception ex)
{
}
}
...
I dont know why it is throwing an Exception. I hope the Information that I have given is enough. If not please get back to me :-)
Thank you in advance for your answer