I have a WPF application which uses a WPF user control.
The user control exposes a DependencyProperty to which I would like to bind to in my WPF application.
As long as my user control does not set its own DataContext this works and I am able to listen to changes in the DependencyProperty.
However the moment I set the DataContext the PropertyChanged being called is null.
What am I missing here?
Code sample:
https://skydrive.live.com/redir.aspx?cid=367c25322257cfda&page=play&resid=367C25322257CFDA!184
DependencyPropertyhas inheritance property, so if you don’t set the UserControlDP’s DataContext, the DataContext is inherited from the MainWindow’s DataContext. In this case, the UserControlDP’s DataContext in your code below is set asMainWindow_ViewModel. Thus, the binding is correctly executed.In the other case, UserControlDP’s DataContext is set as UserControlDP_ViewModel, so the binding is broken. You can see the first exception message as the following at the debug window.