I need something to get the position of a sub-sub element relative to the container. TransformToAncestor does that. However, the element and subelements move, resize change, their layout, etc. I need a way to keep the position up-to-date. Like an event if anything happend that would affect my TransformToAncestor operation. Or an “AbsolutePosition” dependency property I can bind to.
Background:
I’m doing sort of a work flow editor.
There are ‘modules’ that have one or more ports and lines that connect the modules from port to port.
The XAML stucture looks like this:
<Canvas>
<Module Left="..." Top="..." Width="..." Height="...">
<Grid><otherelement><somemorelayouting>
<Port Name="a" />
<Port Name="b" />
</somemorelayouting></otherelement></Grid>
</Module>
<Module Left="..." Top="..." Width="..." Height="...">
<differentsetoflayouts>
<Port Name="c" />
<Port Name="d" />
</differentsetoflayouts>
</Module>
<Line startpoint="{binding source=a, path=abs_position}" endpoint="{binding source=c, path=abs_position}" />
</Canvas>
The line connects port a of the first module with port b of the second. The end points should be at the top left corner of the port-element (for the moment). This “abs_position” property used in this example does unfurtunatly not exist (I’m using start/endpoint here instead of X1,X2,Y1,Y2 only to improve readability)
If you implement your container with attached dependency properties for location of children elements (like the Canvas panel does, which seems to be the case according to provided code), then you can bind to changes of that dependency property using a DependencyPropertyDescriptor.