Alex Shindich

Alex Shindich shindich

Niner since 2008


  • WPF 3.5 SP1 App Model with Jennifer Lee

    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"



        Height="Auto" Width="Auto">

        <WebBrowser Name="mWebBrowser">



    C# code (MyWebBrowser.cs):

    public partial class MyWebBrowser


        public MyWebBrowser()





        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;




        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;





    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\>}"/>