Anton__


lest say I have MyObject.MyDp DP. with a registered PropertyChangedCallback in the FrameworkPropertyMetadata

MyObject myObj = new MyObject();
myObj.SetValue(MyObject.MyDp, 10); // At this point the PropertyChangedCallback will be hit
myObj.SetValue(MyObject.MyDp, 10); // But not here

How can I make it so on the second assignment the PropertyChangedCallback will get hit even though the value is not actually changing Maybe PropertyChangedCallback is not suitable for that purpose. if so, which other callback can I use

Thanks
Anton


Re: Windows Presentation Foundation (WPF) Dependency Property PropertyChangedCallback invocation problem

Drew Marsh

Yeah, the value's not really changing so the DP system optimizes the call away (a "good thing"). What you need to do is take it a step further and provide a SetValueOverride for the PropertyMetadata.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) Dependency Property PropertyChangedCallback invocation problem

Anton__

Hm.. I'm using DPs from System.Windows and they dont have SetValueOverride callback in the PropertyMetadata.
Can I just switch to System.Workflow.ComponentModel area classes from this namespace compatible with classes from System.Windows/Data




Re: Windows Presentation Foundation (WPF) Dependency Property PropertyChangedCallback invocation problem

Drew Marsh

Ooops, sorry you're right. I forgot they have their own dependency property system. No they're not interchangeable, I just didn't notice that I was on the WWF PropertyMetadata when I did my search.

There's definitely a way to do this with WPF, let me look around and get back to you.

-Drew





Re: Windows Presentation Foundation (WPF) Dependency Property PropertyChangedCallback invocation problem

Drew Marsh

Strange, there used to be ways to do this back in the beta days, but they don't seem to exist anymore. They're there in WWF (SetValueOverride for example), but WPF seems to have dropped them. You might want to look at setting a CoerceValueCallback on your DP. This will be called prior to the property actually being set.

I guess the real question is, what exactly are you trying to do Why do you care if the property is set to the same value again

Cheers,
Drew





Re: Windows Presentation Foundation (WPF) Dependency Property PropertyChangedCallback invocation problem

ivolved_Mike_Brown

I believe that CoerceValueCallback is definitely the route you want to go...it gets called everytime the DP is updated. The coercion system is pretty neat because it acts like a validator, but unlike a validator you get a reference to the object actually being coerced. So for instance if you had a "MaximumValue" and a "MinimumValue" and a "CurrentValue", you would want to set CoerceValueCallbacks on all three, that way if someone tries to set CurrentValue to a value outside your range, your coercion mesh would handle it properly. There were a few good articles on it, but I'm too lazy to search for them right now




Re: Windows Presentation Foundation (WPF) Dependency Property PropertyChangedCallback invocation problem

Anton__

I have a set of properties dependent on each other. the update algorithm needs to know which of the props was updated last. when the value of the property is assigned - even if there was no actual change I need to save the information about the assignment - step into the validation callback.

I actually workarounded that introducing second auxiliary variable which holds the info about the previous assignment, but I'd love to simplify the code.

I'll try CoerceValueCallbackThough