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.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,672 questions
Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
179 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 27,796 Reputation points Microsoft Vendor
    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