Property order precedence

I've pretty quiet lately -- working hard getting ready for the PDC!  Getting the next CTP ready is taking quite a bit of my time, and put that together with a PDC talk, and you get a Nick that hasn't read e-mail in a week.  But I'm getting excited, the talk's not done yet but I'm see the light at the end of the tunnel.  And I had a great time putting together the sample of data binding from Avalon to MFC (sorry, you're just going to have to wait for that one).  The other presentations are coming along as well, and there's some great new functionality in the next CTP (whenever that is exactly).

And of course, we have a new product name --Windows Presentation Foundation!  Okay, so I'll admit I'm not super excited about that particular name, but I am excited that we have an official name, because that's a sure sign the ship date is getting close!

Anyhow, someone suggested awhile back that I write a bit about dependency properties.  That's probably good for several blogs, but I'll start with a quick discussion about precedence.  Dependency properties can get their values from a number of different places.  We search in this order:

  • Local value (ie, <Object Property="value">
  • Property triggers
  • TemplatedParent's template (ie, that template includes <Setter>s)
  • Style property
  • ThemeStyle
  • Inheritance ("property inheritance" -- from your parent element, not your superclass)
  • DefaultValue specified when you registered the property (or override metadata)

Actually, that's just to find the base value -- GetValue will then apply any applicable animations to that base value to give you the computed value.  So animations can trump even local values.

Note also that inheritance is simply calling GetValue on the parent element.  So if you have the parent and child element, and neither of them specify the value for the property except through default value, and those two elements have different concepts of what the default value should be (through the magic of OverrideMetadata) -- you'll get the parent's answer, not the child.  Because the child says, "hey parent, what value are using?"  And the parent answers, and the child never looks at its own default value.