Текст исчезнет в режиме дизайна веб-браузера - PullRequest
0 голосов
/ 06 марта 2019

Я работаю над приложением Wpf и использую веб-браузер для отображения html в режиме разработки. Как ни странно, часть текста исчезает и это видно при выделении текста. Или Если я использую браузер с выключенным режимом дизайна.

Ссылка для обмена кодом: https://1drv.ms/u/s!Ahr8XhqVvaXge4O2x_NLoHExCtU

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        HtmlEditor.Loaded += HtmlEditor_Loaded;

HtmlEditor.NavigateToString(@"<!DOCTYPE HTML PUBLIC 



""-//W3C//DTD HTML 4.0 Transitional//EN"">
<html><head>
<meta content=""text/html; charset=unicode"" http-equiv=""Content-Type"" />
</head>
<body>
</body></html>");
        }
    private void HtmlEditor_Loaded(object sender, RoutedEventArgs e)
    {
        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(() => { }));

        IHTMLDocument2 msHtmlDoc2 = HtmlEditor.Document as IHTMLDocument2;
        if (msHtmlDoc2 != null && string.Equals(msHtmlDoc2.designMode, "On", StringComparison.OrdinalIgnoreCase) == false)
            msHtmlDoc2.designMode = "On";


        var myDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        var htmlFile = Path.Combine(myDir, "test.html");
        var html = File.ReadAllText(htmlFile);

        msHtmlDoc2.write(html);
        msHtmlDoc2.close();
    }
}

Ниже приводится содержание файла html. Это происходит только тогда, когда я использую фон для div или добавляю дополнительный span после текста «Hello».

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title></title>
	<meta content="text/html; charset=unicode" http-equiv="Content-Type" />
</head>
<body>
<div style = "background-color: #f0fff0" >
	<p><span style="font-size: 11pt"><span style = "font-family: arial, helvetica, sans-serif" > Hello </span></span></p>
	<p><span style="font-size: 11pt"><span style = "font-family: arial, helvetica, sans-serif" ></span></span> &nbsp;</p>
	<p><span style = "font-size: 11pt" ><span style="font-family: arial, helvetica, sans-serif"></span></span>&nbsp;</p>
	<p><span style = "font-size: 11pt" ><span style="font-family: arial, helvetica, sans-serif"></span></span>&nbsp;</p>
	<p><span style = "font-size: 11pt" ><span style="font-family: arial, helvetica, sans-serif">, <br /><br /><b><u>Issue
			#1</u></b><br />place the cursor behind the space after the comma in the first 
		line(the very last position in line 1) and press[Return] <b>twice</b>.<br />You
		will see that the green background pane(from div id #GreenBox) breaks 
		somehow.<br /><br /><br /><b><u>Issue #2</u></b><br />place the cursor direct 
		<b> before</b> the comma in the first line and press[Return]
		<b>once</b>.<br />Then place the cursor direct behind Hello again and press
		[Return] <b>twice</b>.You will see the word Hello become invisible, but the
		text is still there (e.g.select to unhide it).<br />When you switch to preview
		mode, the content will be displayed normal, switch back to design and Hello
		disappears again. </span></span></p>
	<p>Best regards,<br />Alexander.</p></div></body></html>
...