ComponentFactory.Quicksilver.Layout.CanvasLayout.TargetChildren C# (CSharp) Method

TargetChildren() public method

Calculate target state for each element based on layout algorithm.
public TargetChildren ( string layoutId, MetaPanelBase metaPanel, MetaElementStateDict stateDict, ICollection elements, Size finalSize ) : void
layoutId string Identifier of the layout to be used.
metaPanel MetaPanelBase Reference to owning panel instance.
stateDict MetaElementStateDict Dictionary of per-element state.
elements ICollection Collection of elements to be arranged.
finalSize System.Windows.Size Size that layout should use to arrange child elements.
return void
        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;
                        }
                    }
                }
            }
        }
        #endregion