RStyle
RStyle

Reputation: 885

WPF vs Windows WebBrowser Control

In Windows Form Web Browser Control, if i have a String variable containing text, i can use memory stream to display the data via Webbrowser.documentstream.

However in WPF Web Browser Control, if I use the same technique via , nothing shows up. But the "view source page" contains the text.

How do i solve this?

        Byte[] bytes = Encoding.Unicode.GetBytes(code);


        MemoryStream ms = new MemoryStream(bytes);

        //webBrowser.Navigate("http://www.wpf-tutorial.com");
        webBrowser.NavigateToStream(ms);

code store the following string

@"
<div style="color:Black;background-color:White;"><pre>
<span style="color:Blue;">using</span> System;
<span style="color:Blue;">using</span> System.Collections.Generic;
<span style="color:Blue;">using</span> System.Linq;
<span style="color:Blue;">using</span> System.Text;
<span style="color:Blue;">using</span> System.Threading.Tasks;

<span style="color:Blue;">namespace</span> ColorCodeTest{    
    <span style="color:Blue;">class</span> Program
    {
        <span style="color:Blue;">static</span> <span style="color:Blue;">void</span> Main(<span style="color:Blue;">string</span>[] args)
        {
            Console.WriteLine(<span style="color:#A31515;">&quot;&amp;lt;WTF&gt;&quot;</span>);
        }
    }
}

</pre></div>"

Upvotes: 3

Views: 327

Answers (1)

Mark Feldman
Mark Feldman

Reputation: 16119

Works for me, must be something wrong with the text itself? Try running the code though HtmlEncode before passing it in to the control:

code = System.Web.HttpUtility.HtmlEncode(code);

Upvotes: 1

Related Questions