In a DockPanel subclass's ArrangeOverride method, the first thing we do is call the base implementation as that's who handles the actual arrangement. However, without going into the 'why' here (as it's not relevant to the question), we then need to get the Rect which the base implementation of ArrangeOverride passed to the Arrange method of the last child.
Is there any way to query a UIElement to see what rect was passed to its Arrange method?
For instance...
protected override Size ArrangeOverride(Size arrangeSize)
{
// Perform default arrangement
var retVal = base.ArrangeOverride(arrangeSize);
// Get the last element (if any)
var lastElement = Children.OfType<UIElement>().LastOrDefault();
// Get the Rect passed to the lastElement in the base.ArrangeOverride call
var lastElementArrangeRect = (lastElement != null)
? lastElement.ArrangeRect // <-- This is what we're looking for
: new Rect();
return retVal;
}
The only way we have found is to re-implement ArrangeOverride ourselves as we would then obviously know the Rect used. However, we're trying to have code that will work with any panel subclass.