Click here to Skip to main content
15,610,223 members
Articles / Programming Languages / C#
Posted 28 Nov 2016

Tagged as


7 bookmarked

WPF WebBrowser Control Enhancements

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
28 Nov 2016CPOL2 min read
The WPF WebBrower control leaves a lot to be desired.


The WPF WebBrowser control is extremely sad in the capabilities it provides, and even in supporting the MVVM pattern. I created a control to enhance the capabilities of the WebBrower to support easy interface using ICommand for forward and back buttons, and the MVVM design pattern. Since Microsoft made things even sillier because the WebBrowser is Sealed, I had to inherit from the ContentControl and this ContentControl only contains a WebBrowser control.

The following are the capabilities this control has:

  • NavigateString (string) DependencyProperty which will execute the WebBrowser Navigate method.
  • HeaderString (string) DependencyProperty which will set the cookies for the brower. The string contains the cookie items separated by a ";" with each cooking being the key, an equal sign ("=") and then the value.
  • An IsSuccessful DependencyProperty that is set to null when navigation is started, and then changes to true if it appears that the navigation was successful, and false is not. The way it is determined that the navigation was not successful is if the Document Url property starts with "res://ieframe.dll".
  • A Body DependencyProperty that will allow the content of the WebBrowser to be defined by a string containing HTML.
  • A BrowseForward and BrowseBack ICommand that allows a Button to be bound to the WebBrowserControl for navigation forward and back.
  • The silencing of error messages by the browser that are probably due to javascript errors (I was having a lot of trouble with this on some sites I browsed to).
  • A way to discover and update the Internet Explorer browser version used by the control.
  • Ability to disable/enable WebBrowser ContextMenu (disabled by default)

Using the code

This is an example of using the control using the MVVM design pattern

<local:WebBrowserControl x:Name="Browser"
                         HeaderString="{Binding WebCookies}"
                         IsSuccessful="{Binding IsSuccessful, Mode=OneWayToSource}"
                         NavigateString="{Binding WebUri}" />


The sample uses the URI "" because this will show the cookies.

Image 1

The sample above has red boxes to show where the token information can be found.


This control could be significantly enhanced, but includes a lot of snippets that should be quite useful to anyone trying to implement a WebBrowser in WPF, and also is a good template for implementing enhancements. If anyone has any thoughts on how this can be improved, I am definitely interested.


  • 2016-11-28: Initial Version
  • 2017-01-20: Added abiltiy to remove WebBrowser ContextMenu (thanks to code provided by Simon Mourier


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior) Clifford Nelson Consulting
United States United States
Has been working as a C# developer on contract for the last several years, including 3 years at Microsoft. Previously worked with Visual Basic and Microsoft Access VBA, and have developed code for Word, Excel and Outlook. Started working with WPF in 2007 when part of the Microsoft WPF team. For the last eight years has been working primarily as a senior WPF/C# and Silverlight/C# developer. Currently working as WPF developer with BioNano Genomics in San Diego, CA redesigning their UI for their camera system. he can be reached at

Comments and Discussions

GeneralMy vote of 5 Pin
Farhad Reza2-Dec-16 6:13
Farhad Reza2-Dec-16 6:13 
AnswerRe: My vote of 5 Pin
Clifford Nelson2-Dec-16 9:25
Clifford Nelson2-Dec-16 9:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.