WPF WebBrowser Control Not Rendering External HTML Content Properly
Good day Team,
Cheers!
I'm currently working on a project to show some information about settings to a WPF WebBrowser control. The project also has the ability to produce a report in an .html file that can be viewed through the browser by the clients. Upon comparing the results from both the .html file and the file rendered to the webbrowser, I noticed that the html file is broke when rendered. Some of the borders are missing and some of the colors are not reflecting. Upon doing some research, I found a solution that is to change the meta tag to use the MS edge engine. When I verified my code to dynamically generate the html file, I noticed that the code to set the meta tag uses plain text/html content such as the code below.
private void WriteOpenMainTags(string prevFile, string currFile, ref StringBuilder openMaintags) { openMaintags.AppendLine("<!DOCTYPE HTML>"); openMaintags.AppendLine("<html>"); openMaintags.AppendLine("<head>"); openMaintags.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"); openMaintags.AppendLine("<title>FirewallRuleSet Compare</title>"); WriteStyles(ref openMaintags); openMaintags.AppendLine("</head>"); openMaintags.AppendLine("<body>"); openMaintags.AppendLine("<div class=\"AlignCenter\"><h2>FirewallRuleSet Files Compare</h2></div>"); openMaintags.AppendLine($"<div>Produced: {DateTime.Now.ToString("dddd, MM/dd/yyyy hh:mm tt")}</div>"); openMaintags.AppendLine("<div>Mode: Differences, With Context, Ignoring Unimportant </div>"); openMaintags.AppendLine($"Left File: {prevFile} Right File: {currFile} "); }
Updating the meta tag from:
openMaintags.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
to the code below which is setting the http-equiv to X-UA-Compatible and content to IE=edge, solved the issue. My WPF webbrowser control renders the .html file same with the standard browsers (Chrome, Edge, Firefox).
openMaintags.AppendLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />");
Cheers!
Comments
Post a Comment