Silverlight 4 – HtmlBrush

Silverlight’s HtmlBrush is an alternative to the WebBrowser control for displaying HTML content in Silverlight app. There are two primary differences between the HtmlBrush and WebBrowser controls :

  1. WebBrowser can display “live” content, whereas the HtmlBrush only display static html content
  2. HtmlBrush can have transforms applied to it, so for visual effects this is the control of choice.

The below sample shows how to paint a simple rectangle with the HtmlBrush:

You can render HTML content with HtmlBrush, too. The following XAML snippet ‘paints’ a Rectangle with an HTML page.

<WebBrowser Name=”demoWB” Source=”/silverlightace.htm”  />
<Rectangle Canvas.Left=”1″ Canvas.Top=”20″ Height=”100″ Width=”100″>
<Rectangle.Fill>
<HtmlBrush SourceName=”demoWB” x:Name=”demoBrush” />
</Rectangle.Fill>
</Rectangle>

This entry was posted in FAQ and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>