Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView2 Source property doesn't initiate CoreWebView2

Tags:

c#

wpf

webview2

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.

like image 814
wellinthatcase Avatar asked Apr 20 '26 19:04

wellinthatcase


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.

like image 115
Poul Bak Avatar answered Apr 23 '26 09:04

Poul Bak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!