/// <summary>
/// Calculate target state for each element based on layout algorithm.
/// </summary>
/// <param name="layoutId">Identifier of the layout to be used.</param>
/// <param name="metaPanel">Reference to owning panel instance.</param>
/// <param name="stateDict">Dictionary of per-element state.</param>
/// <param name="elements">Collection of elements to be arranged.</param>
/// <param name="finalSize">Size that layout should use to arrange child elements.</param>
public override void TargetChildren(string layoutId,
MetaPanelBase metaPanel,
MetaElementStateDict stateDict,
ICollection elements,
Size finalSize)
{
// Only apply if we match the incoming layout identifier
if (string.IsNullOrEmpty(Id) || Id.Equals(layoutId))
{
// Calculate the target rectangle for each element
foreach (UIElement element in elements)
{
// We ignore items being removed
if (stateDict[element].Status != MetaElementStatus.Removing)
{
// Default to being the desired size but at position zero,zero
Rect newTargetRect = new Rect(0, 0, element.DesiredSize.Width, element.DesiredSize.Height);
// Use the Left or Right value provided as attached properties of the element
double left = CanvasLayout.GetLeft(element);
if (!double.IsNaN(left))
{
newTargetRect.X = left;
}
else
{
double right = CanvasLayout.GetRight(element);
if (!double.IsNaN(right))
{
newTargetRect.X = (finalSize.Width - element.DesiredSize.Width) - right;
}
}
// Use the Top or Bottom value provided as attached properties of the element
double top = CanvasLayout.GetTop(element);
if (!double.IsNaN(top))
{
newTargetRect.Y = top;
}
else
{
double bottom = CanvasLayout.GetBottom(element);
if (!double.IsNaN(bottom))
{
newTargetRect.Y = (finalSize.Height - element.DesiredSize.Height) - bottom;
}
}
// Store the new target rectangle
if (!stateDict[element].TargetRect.Equals(newTargetRect))
{
stateDict[element].TargetChanged = true;
stateDict[element].TargetRect = newTargetRect;
}
}
}
}
}