So If I have a binding placed on width of a child object that links it to its parent's ActualWidth
, what will happen?
My guess is that the parent measures how much width the child wants, the child tells the parent 0 width, then the parent is given actual space during arrange, and it attempts to give the child zero since the child didn't want any. Then the actual width of the space given to the parent should cause the binding to change the child's width. At this point I would guess layout is performed again.
However, this assumes that the binding doesn't propagate that fast. I'm still hazy on when the bound value propagates to the target. It all depends on when the parent's actualwidth value changes. Does this occur after layout finishes? and then the bound pieces update? Does every binding interrupt the currently running code to go update the target value? if not, wouldn't it cause problems if one binding propagates a change that requires a redraw, then another binding propagates a different change that causes redraw, etc.
Some people asked what my actual problem was:
So originally I wanted to have a control stretch to fill the available space. Simple enough, but I wanted to have it be in a scrollviewer. Scrollviewer gives infinite space to its children during measure. So instead you can bind the width and height of the child control to the parent's actualwidth and actual height; layout does a second pass, and all seems swell.
However, later I was having issues of a similar kind stretching a control in a controltemplate but then found out that I can set a minwidth and alignment=stretch to have it stretch.
However, I distinctly remembered trying that earlier on my other control and having it not work, so I went back and tried to figure out what the difference between the two cases was. Basically it boiled down to one of them being in a stackpanel a few levels up.
So now I am using a binding for one and the minwidth plus alignment method for the other. Anyway was only interested in this to make sure that the way i'm doing things doesn't create weird bugs later.
I am hoping that layout doesn't run immediately when a width or height is changed but instead the system rechecks for size changes periodically