WPF DependencyProperty event before content changed
- by morsanu
First I will explain the context of the problem, because you might be able to point me in a better direction.
I need to implement a undo-redo like system on an object. The object has a series of dependency properties. Some are double, int, string but some are also of DependencyObject type.
I need to save the value of the property before it is changed, and for this I added the CoerceValueCallback.
public static readonly DependencyProperty MyBackgroundProperty =
DependencyProperty.Register("MyBackground", typeof(MyCustomizableBackground),
typeof(MyComponent), new UIPropertyMetadata(default(MyCustomizableBackground), null, new CoerceValueCallback(OnPropertyChanged)));
In OnPropertyChanged I save the value before it's changed. MyCustomizableBackground is the DependencyObject that has also some dependency properties.
The problem is that in this case, where I have a custom object as a property, the OnPropertyChanged method isn't triggered, but when I have a common type, it is triggered.