When setting attached properties, the value is stored in the element only, not the type the attached property belongs to.
For example, the attached row property is implemented like this:
public static readonly DependencyProperty RowProperty = ...;
public static void SetRow(UIElement element, int value)
{
element.SetValue(RowProperty, value);
}
public static int GetRow(UIElement element)
{
return (int)element.GetValue(RowProperty);
}
So when you call Grid.SetRow
, then internally element.SetValue
is called. As element
is a dependency object, it can store those additional properties. You can imagine it as Dictionary<DependencyProperty, object>
inside the dependency object (albeit it’s a lot more complex in fact) which you can access using SetValue
and GetValue
.
So the value is only stored inside of the dependency object itself. Now, when the Grid renders itself, it will iterate through its children to call its measurement and layout routines. It will also call Grid.GetRow
for each of those children to see if the attached row property was set, and respect those choices during its own layout phase accordingly.