DependencyObjectdoes not implement INotifyPropertyChanged, therefore, if you take this route, you will have to implement the dispatch of PropertyChanged events manually.
Fortunately, it DependencyObjecthas a method OnPropertyChanged, so the implementation INotifyPropertyChangedin your- DependencyObjectderived class is trivial, for example:
public class MyClass : HeaderedContentControl, INotifyPropertyChanged
{
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
var handler = PropertyChanged;
if(handler!=null) handler(this, new PropertyChangedEventArgs(e.Property.Name));
base.OnPropertyChanged(e);
}
public event PropertyChangedEventHandler PropertyChanged;
}
I would like echo jsmith to think that binding directly to the UserControl property cannot be the best way. In most cases, MVVM is the best way to go. Of course, there are exceptions.
source
share