CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.

Home Page:https://aka.ms/windowsappsdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] WPF Web View InvokeScript Unkown Name Error

BEDIRHANSAMSA opened this issue · comments

I have a Webview. I am trying to run a script while specifying the content of the webview in the constructor in my class and as soon as the web view loads the content. But it gives error. I create a button, when I press it, the script working. But I want to do it without a button. How can I fix this error?

Code:

public HtmlEditor(string html)
{
    InitializeComponent();
    WebView.NavigationCompleted += (sender, args) =>
    {
        // Throws here
        WebView.InvokeScript("setHtml", html);
    };

    WebView.Loaded += (sender, args) =>
    {
        var uri = new Uri("Resource\\RichText.html", UriKind.Relative);
        WebView.NavigateToLocalStreamUri(uri, new UriResolver());
    };

}

Html:

<script>
    function setHtml(html){
        this.quill.clipboard.dangerouslyPasteHTML(html);
    }


    function getText(){
        console.log(this.quill.root.innerHTML);
        return this.quill.root.innerHTML;
    }
</script>

Error:

System.AggregateException: '255.255.255.255s: 6=1819, HWND=0x00060F68.Utility.CountToValueConverter`1[[Sy)'
Exception: Unknown name. (0x80020006 (DISP_E_UNKNOWNNAME))