WebView2 Source property doesn't initiate CoreWebView2

Viewed 1941

I've spent half an hour trying to figure out this tedious issue where you're unable to Navigate strings unless the Source property is set.

After all, I figured out a workaround hack since WebView2 demands an absolute path to an html file or nothing else.

Markdown.Focus(); 
Markdown.BringIntoView();

Markdown.Source = new Uri(Path.GetFullPath("null.html"), UriKind.Absolute);
Markdown.Visibility = Visibility.Visible;

Markdown.NavigateToString(htContent);

Even after all of this. It still says "You need to set the Source property!!". This is driving me nuts.

null.html is a valid html file too. It's just empty since the HTML I need to display is way too dynamic to buffer into a file.

1 Answers

Instead of the code, you have, try this:

await Markdown.EnsureCoreWebView2Async();
Markdown.NavigateToString(htContent);

Now you don't have to set the Source property.

BTW: You don't have to set the other properties either, the WebView2 Control is automatically displayed.

Related