Jan 19, 2009

WebBrowser in WPF


Sketching a very simple RSS reader for a demo today, I just faced the question on how to display HTML in the Windows Forms WebBrowser control in a WPF application.

You just need to wrap it into a WindowsFormsHost element:




<DockPanel Grid.Column="1" Margin="10" TextBlock.FontFamily="Verdana" >


    <TextBlock FontSize="16" FontWeight="Bold" x:Name="RssTitle" DockPanel.Dock="Top"/>


    <WindowsFormsHost>


        <wf:WebBrowser x:Name="RssBrowser" />


    </WindowsFormsHost>


</DockPanel>




Setting the namespace for wf to

xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"




and then call

this.RssBrowser.DocumentText = syndicationItem.Summary.Text;



from code. Does anybode know how to set the font family, by the way?

No comments:

Post a Comment