1

I use System.Windows.Controls.WebBrowser in my WPF, MVVM application.

I need to let ViewModel of WebBrowser know when Source property of WebBrowser changed, respectively when loaded html document changed. Of course, the best way is binding of Source property to ViewModel, but I found just this solution for binding, which provides only one-way binding from ViewModel to WebBrowser: databind the Source property of the WebBrowser in WPF

Old WebBrowser from namespace System.Windows.Forms has such a useful methods like "OnDocumentTitleChanged", but I can not find anything similar in System.Windows.Controls.WebBrowser.

Community
  • 1
  • 1
Volt
  • 127
  • 2
  • 14

1 Answers1

0

Try listening to WebBrowser.Navigated & WebBrowser.Navigating and send a Message in code behind to you VM with the WebBrowser.Source and listen to it on your VM and process it unless you want to go hardcore MVVM, a EventToCommand on one of the 2 events are possible to.

Tom Kerkhove
  • 2,151
  • 5
  • 26
  • 42
  • Thank you, I´m quite newbie for "listening", please can you give me a sample of code of listening to WebBrowser.Navigating for example? Thank you very much. – Volt Jun 18 '12 at 13:52
  • For using MVVM, I recommend using the MVVM Light Framework you can find here - mvvmlight.codeplex.com Your WebBrowser in XAML : http://pastebin.com/Kt64FUbp Your code behind : http://pastebin.com/WzuDwVyD Your Viewmodel : http://pastebin.com/GZ4XRZAv – Tom Kerkhove Jun 18 '12 at 14:05