Listen to DependencyProperty changed event and get the old value
You can do that when you register your dependency property in the attached event handler. Please find below the syntax for a dependency property and how to get the old value on PropertyChanged
event handler:
//Declaration of property
public static readonly DependencyProperty MyNameProperty =
DependencyProperty.Register("MyName",
typeof(PropertyType),
typeof(ClassName),
new PropertyMetadata(null,
new PropertyChangedCallback(MyNameValueChanged)));
//PropertyChanged event handler to get the old value
private static void MyNameValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
{
object oldValue = eventArgs.OldValue; //Get the old value
}
Unfortunately, you don't get old value information when registering property changed event handler this way.
One workaround is to store property value somewhere (this is your 'old' value) and then compare it to current value in the event handler.
Another workaround is to create your own dependency property (DP) and create binding between your DP and the control's DP. This will give you change notification in the WPF style.
Here is an article about this.