To my knowledge, there is no 'PreviewPropertyChanged' that you can subscribe to for a dependency property, but I need to know a value WILL be changing. My thought is to sort of re-purpose the Coerce Value method and do my check there (naturally after any actual coercion takes place since it makes sens that gets called before the actual change takes place. That way I can check the existing value versus the coerced value to determine a change, and if there is one, then fire my Preview' code. This the correct way to do this or am I missing something?
Asked
Active
Viewed 147 times
1 Answers
1
You got it. The CoerceValueCallback is a good way to raise an "XXXChanging" event, which gives consumers of the object a change to change the value or cancel the change. Your coerce would then return the new value, or the modified value. You can get the old value directly from the DependencyObject, as it's not included in the CoerceValueCallback parameters.
On a side note, "Preview" events are tunneling events. This means they go from the top of the tree down. Bubbling events go from the bottom up. So I would avoid calling it PreviewPropertyChanged, as that implies the property has already changed and it is a tunneling event.

CodeNaked
- 40,753
- 6
- 122
- 148
-
Yep... I know that about the tunneling/bubbling. I'm just looking for something on the same control so neither really matters. BUT... I wanted to be notified BEFORE it changes because this DP is used to switch other values via triggers and I have to get to those values before the trigger fires, hence the need to be 'previewed'. I'm not actually doing any coercion at all. Just wanna do something before those damn triggers fire! – Mark A. Donohoe Apr 15 '11 at 16:46
-
@MarqueIV - Yeah, the CoerceValueCallback would be the way to go. You can even prevent the PropertyValueChangedCallback and triggers from firing, if you return the old value. – CodeNaked Apr 15 '11 at 17:08
-
I just posted another question related to this here... http://stackoverflow.com/questions/5680101/in-wpf-for-a-dp-is-there-any-way-to-use-a-function-to-return-the-default-value. Wanna take a stab at it? – Mark A. Donohoe Apr 15 '11 at 17:12