How to display complex HTML content in WPF

Ankita 0 Reputation points
2023-04-10T13:35:13.2766667+00:00

I am working on Visual Studio 2022 VSIX project. I have HTML content which I needs to bind in XAML. I have used WebBrowser control. It is working fine with simple HTML. But when I tried to load dynamic data with complex HTML then it gives Script error. Please suggest any other control to display HTML data. Thanks in advance.

Developer technologies Visual Studio Extensions
Developer technologies Visual Studio Other
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,436 Reputation points Microsoft External Staff
    2023-04-17T13:57:59.79+00:00

    Hi @Ankita,

    This issue seems to be caused by WebBrowser control(it renders pages in compatibility mode by default - IE). See if adding this tag to the header works => <meta http-equiv="X-UA-Compatible" content="IE=Edge" />.

    Also, please check if this document: Controlling WebBrowser Control Compatibility helps.

    There are also some methods to suppress this error, for example => adding webBrowser.ScriptErrorsSuppressed=true;.

    Perhaps you can consider using other control like WebView2.

    BTW, on my side, the script error appeared no matter using <link href="/resources/sample.css" rel="stylesheet" /> or using <link href="http://localhost:XXXX/resources/sample.css" rel="stylesheet" />.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.