Pages

Friday 26 November 2010

How to show a dynamically generated HTML content in a WPF application

If you have to show dynamically generated .html pages in your WPF application you can use a WebBrowser control. NavigateToString("...") method gives you full flexibility and navigates asynchronously to a string which contains the content for a document.


   1:  <Window x:Class="WpfApplication1.MainWindow"
   2:          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:         xmlns:local="clr-namespace:WpfApplication1"
   5:          Title="MainWindow" Height="350" Width="525">
   6:      
   7:      <Window.Resources>
   8:          <WebBrowser x:Name="browser"/>
   9:      </Grid>
  10:  </Window>

   1:   public partial class MainWindow : Window, IDataErrorInfo, INotifyPropertyChanged
   2:      {
   3:          public MainWindow()
   4:          {
   5:              InitializeComponent();
   6:              browser.NavigateToString("<html><head><h1>Head</h1></head><body>" + DateTime.Now + "</body></html>");
   7:          }
   8:     }

No comments:

Post a Comment