I wrote a usercontrol wrapper that uses DependencyProperties:
XAML:
<UserControl x:Class="HtmlBox"> <WebBrowser x:Name="browser" /> </UserControl>
FROM#:
public static readonly DependencyProperty HtmlTextProperty = DependencyProperty.Register("HtmlText", typeof(string), typeof(HtmlBox)); public string HtmlText { get { return (string)GetValue(HtmlTextProperty); } set { SetValue(HtmlTextProperty, value); } } protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { base.OnPropertyChanged(e); if (e.Property == HtmlTextProperty) { DoBrowse(); } } private void DoBrowse() { if (!string.IsNullOrEmpty(HtmlText)) { browser.NavigateToString(HtmlText); } }
and use it like this:
<Controls:HtmlBox HtmlText="{Binding MyHtml}" />
The only problem with this is that the WebBrowser control is not a "clean" wpf ... in fact it is just a wrapper for the win32 component. This means that the control will not respect the z-index and will always overlap another element (for example: in scrollviewer this may cause some problems) more information about these win32-wpf problems on MSDN
RoelF Jun 10 '09 at 15:19 2009-06-10 15:19
source share