예제 #1
0
        private Rect[] CalculateItemRects(Size availableSize)
        {
            var    itemRects = new Rect[this.InternalChildren.Count];
            double offset    = 0;

            for (int i = 0; i < this.childrenLengths.Length; i++)
            {
                SplitPanelLength length = this.childrenLengths[i];
                if (this.Orientation == Orientation.Horizontal)
                {
                    double width = length.IsAbsolute
                                       ? length.Value
                                       : Math.Max(0, (availableSize.Width - this.childrenLenghtFixed) * length.Value);
                    itemRects[i] = new Rect(offset, 0, width, availableSize.Height);
                    offset      += width;
                }
                else if (this.Orientation == Orientation.Vertical)
                {
                    double height = length.IsAbsolute
                                        ? length.Value
                                        : Math.Max(0, (availableSize.Height - this.childrenLenghtFixed) * length.Value);
                    itemRects[i] = new Rect(0, offset, availableSize.Width, height);
                    offset      += height;
                }
            }

            return(itemRects);
        }
예제 #2
0
        private SplitPanelLength GeOffsetLength(UIElement element, double offestDelta)
        {
            SplitPanelLength elementLength = GetLength(element);

            if (elementLength.IsStar)
            {
                double elementRenderLength = this.GetRenderLength(element);
                if (elementRenderLength <= 0 || elementLength.Value <= 0)
                {
                    UIElement foundChild = (from UIElement child in this.InternalChildren
                                            let length = GetLength(child)
                                                         where length.IsStar && length.Value > 0
                                                         select child).FirstOrDefault();
                    if (foundChild == null)
                    {
                        return(new SplitPanelLength(1.0, SplitPanelUnitType.Star));
                    }

                    elementRenderLength = this.GetRenderLength(foundChild);
                    elementLength       = GetLength(foundChild);
                }

                return(new SplitPanelLength(Math.Max(0, (elementLength.Value / elementRenderLength) * (elementRenderLength + offestDelta)), SplitPanelUnitType.Star));
            }

            if (elementLength.IsAbsolute)
            {
                return(new SplitPanelLength(elementLength.Value + offestDelta));
            }

            throw new NotImplementedException("SplitPanelUnitType.Auto is not supported");
        }
예제 #3
0
        /// <summary>
        /// Returns a <see cref="String"/> that represents this instance.
        /// </summary>
        /// <param name="length">
        /// The length.
        /// </param>
        /// <param name="cultureInfo">
        /// The culture info.
        /// </param>
        /// <returns>
        /// A <see cref="String"/> that represents this instance.
        /// </returns>
        internal static string ToString(SplitPanelLength length, CultureInfo cultureInfo)
        {
            switch (length.UnitType)
            {
            case SplitPanelUnitType.Auto:
                return("Auto");

            case SplitPanelUnitType.Star:
                if (length.Value == 1.0d)
                {
                    return("*");
                }

                return(Convert.ToString(length.Value, cultureInfo) + "*");
            }

            return(Convert.ToString(length.Value, cultureInfo));
        }
예제 #4
0
 /// <summary>
 /// Sets the value of the Length attached property to a given <see cref="UIElement"/>.
 /// </summary>
 /// <param name="element">
 /// The element on which to set the Length attached property.
 /// </param>
 /// <param name="value">
 /// The property value to set.
 /// </param>
 public static void SetLength(UIElement element, SplitPanelLength value)
 {
     element.SetValue(LengthProperty, value);
 }