I had this scenario where a property was attached to objects but I wanted different default values for different objects. The code made it easy to just check if the property was set or not, then set the default myself. In order to do that, use the DependencyObject.ReadLocalValue instead of DependencyObject.GetValue and then check if the result equals DependencyProperty.UnsetValue. Like this:

return element.ReadLocalValue(MyProperty) == DependencyProperty.UnsetValue;
Of course, this can be used as an extension method for any element and/or property.

Comments

Siderite

<p>Glad I could help. So many blogs disappeared when the technology they referred to fell out of grace. I intend to always keep my blog up.</p>

Siderite

MrkItGuy

<p>Thanks so much for your tip. That help me in my project! I didn't think I can find any help out side of StackOverFlow or ... but i am happy to find it here! Clean and Direct! well done!</p>

MrkItGuy

Post a comment