Sunday 21 November 2010

How to show HTML content in a WPF window

There are two ways to show HTML content in a WPF window using Frame or WebBrowser control. If you want to switch between WPF and HTML content seamlessly the Frame control is a better choice for you. If you need more control over HTML content, examine the object model of the page and/or monitor page navigation you should consider the WebBrowser control. Both these controls show standard Internet Explorer window with all additional features like JavaScript, Dynamic HTML, ActiveX controls.

XAML version:

   1:      <Grid x:Name="grid">
   2:          <Frame Source="" />
   3:          <!--or-->
   4:          <WebBrowser Source=""/>
   5:      </Grid>

C# version:

   1:              Frame frame = new Frame();
   2:              grid.Children.Add(frame);
   3:              frame.Navigate(new Uri(""));
   5:              //or
   7:              WebBrowser browser = new WebBrowser();
   8:              grid.Children.Add(browser);
   9:              browser.Navigate(new Uri(""));

Useful links:

1 comment: