RE: Binding to thenew  WebBrowser control

A poor man's workaround for this problem is to create a user control that wraps the WebBrowser and offers the needed dependency properties. Here is a quick example:

XAML Defenition (MyWebBrowser.xaml):

<UserControl x:Class="RSSTest.MyWebBrowser"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Height="Auto" Width="Auto">

    <WebBrowser Name="mWebBrowser">

    </WebBrowser>

</UserControl>

C# code (MyWebBrowser.cs):

public partial class MyWebBrowser

{

    public MyWebBrowser()

    {

        InitializeComponent();

    }

 

    public WebBrowser WebBrowser { get { return mWebBrowser; } }

 

    public static readonly DependencyProperty StringHtmlProperty =

        DependencyProperty.Register("StringHtml", typeof(string), typeof(MyWebBrowser),

        new PropertyMetadata(new PropertyChangedCallback(OnStringHtmlChanged)));

    public string StringHtml

    {

        get { return (string)GetValue(StringHtmlProperty); }

        set { SetValue(StringHtmlProperty, value); }

    }

 

    private static void OnStringHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

    {

        MyWebBrowser me = (MyWebBrowser)d;

        me.WebBrowser.NavigateToString(me.StringHtml);

    }

 

    public static readonly DependencyProperty UriProperty =

        DependencyProperty.Register("Uri", typeof(Uri), typeof(MyWebBrowser),

        new PropertyMetadata(new PropertyChangedCallback(OnUriChanged)));

    public Uri Uri

    {

        get { return (Uri)GetValue(UriProperty); }

        set { SetValue(UriProperty, value); }

    }

 

    private static void OnUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

    {

        MyWebBrowser me = (MyWebBrowser)d;

        me.WebBrowser.Navigate(me.Uri);

    }

}

 

Binding Examples:

<local:MyWebBrowser Uri="{Binding Path=Link}"/>

<local:MyWebBrowser StringHtml ="{Binding Path=HtmlString}"/>

<local:MyWebBrowser StringHtml="{Binding Path=Description, StringFormat={}&lt;HTML>&lt;BODY\>\{0\}\&lt;BODY\>\&lt;HTML\>}"/>