Ejemplo n.º 1
0
            /// <summary>
            /// Executes an operation on an already existing SiblingLayoutInfo or create it before executing.
            /// </summary>
            private T ExecuteOnSiblingLayoutInfoIfAvailable <T>(IFrameworkElement child, Dictionary <IFrameworkElement, SiblingLayoutInfo> siblingLayoutInfos, Func <SiblingLayoutInfo, T> operation)
            {
                if (!siblingLayoutInfos.ContainsKey(child))
                {
                    siblingLayoutInfos[child] = new SiblingLayoutInfo();
                }

                return(operation(siblingLayoutInfos[child]));
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Get the area (including location) of a child based on the measured size and the layout information of other children in order
            /// </summary>
            /// <param name="availableArea">The child's available area</param>
            /// <param name="childSize">The measured child size</param>
            /// <param name="siblingLayoutInfo">The information about the previously laid out children</param>
            private Rect ComputeChildArea(Rect availableArea, Size childSize, SiblingLayoutInfo siblingLayoutInfo)
            {
                var location = availableArea.Location;

                if (siblingLayoutInfo.IsRightBound && !siblingLayoutInfo.IsLeftBound && !double.IsPositiveInfinity(availableArea.Right))
                {
                    location.X = availableArea.Right - childSize.Width;
                }
                else if (!double.IsNaN(siblingLayoutInfo.Center.X))
                {
                    location.X = siblingLayoutInfo.Center.X - (childSize.Width / 2);
                }

                if (siblingLayoutInfo.IsBottomBound && !siblingLayoutInfo.IsTopBound && !double.IsPositiveInfinity(availableArea.Bottom))
                {
                    location.Y = availableArea.Bottom - childSize.Height;
                }
                else if (!double.IsNaN(siblingLayoutInfo.Center.Y))
                {
                    location.Y = siblingLayoutInfo.Center.Y - (childSize.Height / 2);
                }

                return(new Rect(location, childSize));
            }