I have to admit the WebBrowser control in Silverlight 4 isn’t quite what I expected and needed but at least we have the possibility to display HTML content in Silverlight apps when running out of browser. The implementations has one limitation though – the browser source can’t be databound. It either has to be directing to an URL or you can load HTML by calling NavigateToString method.
Since I wanted to use the web browser control in a datatemplate, the only reasonable way was to create an attached property to WebBrowser control that calls NavigateToString when it changes.
What are attached properties?
In short using attached properties is a great way to extend the functionality of existing classes without the need to subclass them. An attachable property may be very specific allowing it to be attached to only certain classes like WebBrowser for example or a bit more general like Grid.Row and Grid.Column properties that can be attached to any UIElement.
Bindable WebBrowser Control
To use this attachable property, I add BindableWebBrowser.Html to WebBrowser Xaml local:BindableWebBrowser.Html=”{Binding Content}”
