Using attached behaviors
We can resolve the Binding
issue of controls exposing non-dependency properties by using attached behaviors. This technique is a simple matter of registering an attached property, which is implemented as dependency properties in WPF. We can use the attached property as a binding target and whenever the source value changes, we can pass the updated value to the non-bindable property.
To do this, add a new class called WebBrowserAttachedBehavior
and define it as follows:
namespace UsingNonMVVMElements.AttachedBehaviors { using System.Windows; using System.Windows.Controls; public class WebBrowserAttachedBehavior { public static DependencyProperty SourcePageProperty = DependencyProperty.RegisterAttached("SourcePage", typeof(string), typeof(WebBrowserAttachedBehavior), new PropertyMetadata("", OnSourcePagePropertyChanged)); public static string GetSourcePage(DependencyObject obj) ...