Beispiel #1
0
        private void BuildProxyRows()
        {
            // Is there a change to the row definitions?
            if (_rows.IsDirty)
            {
                // Do we need to recreate the proxy array?
                if ((_proxyRows == null) || (_proxyRows.Length != _rows.Count))
                {
                    // Always need at least one row
                    _proxyRows = new DefinitionProxy[Math.Max(1, _rows.Count)];
                }

                // Hook each row into the matching proxy
                for (int i = 0; i < _rows.Count; i++)
                {
                    _proxyRows[i] = new DefinitionProxy(_rows[i]);
                }

                // Our artifical row needs to point at a real row definition
                if (_columns.Count == 0)
                {
                    _proxyRows[0] = new DefinitionProxy(new RowDefinition());
                }
            }
        }
        private void PreTargetStarDefinitions(double size, DefinitionProxy[] proxies, double stars)
        {
            // Find the size that needs allocating to Star defs (by removing Auto/Fixed sizes from incoming total size)
            int starDefs = 0;
            foreach (DefinitionProxy proxy in proxies)
                if (proxy.UserGridUnitType != GridUnitType.Star)
                    size -= proxy.MinSize;
                else
                    starDefs++;

            // Is there any size left to allocate to the Star defs?
            if (size > 0)
            {
                // Handle defs where the allocated space is outside the min/max limits
                foreach (DefinitionProxy proxy in proxies)
                    if (proxy.UserGridUnitType == GridUnitType.Star)
                    {
                        // Only interested if the definition has a defined min or max value
                        if ((proxy.DefUserMin > 0) || (proxy.DefUserMax < double.PositiveInfinity))
                        {
                            // How much size should this definition have based on its Star value
                            double allocateSize = size;
                            if (starDefs > 1)
                                allocateSize = size / stars * proxy.DefUserSize.Value;

                            // If allocated size is less than the defined minimum
                            if ((proxy.DefUserMin > 0) && (allocateSize < proxy.DefUserMin))
                            {
                                // Enfore minimum setting
                                proxy.StarAllocated = true;
                                proxy.MinSize = proxy.DefUserMin;
                                proxy.MeasureSize = proxy.DefUserMin;
                                stars -= proxy.DefUserSize.Value;
                                size -= proxy.MinSize;
                                starDefs--;
                            }
                            else if ((proxy.DefUserMax < double.PositiveInfinity) && (allocateSize > proxy.DefUserMax))
                            {
                                // Enfore maximum setting
                                proxy.StarAllocated = true;
                                proxy.MinSize = proxy.DefUserMax;
                                proxy.MeasureSize = proxy.DefUserMax;
                                stars -= proxy.DefUserSize.Value;
                                size -= proxy.MinSize;
                                starDefs--;
                            }
                        }
                    }

                // Any more Star defs to allocate?
                if ((starDefs > 0) && (size > 0))
                {
                    // Allocate remaining space to remaining star defs according to Star values
                    foreach (DefinitionProxy proxy in proxies)
                        if ((proxy.UserGridUnitType == GridUnitType.Star) && !proxy.StarAllocated)
                        {
                            // How much size should this definition have based on its Star value
                            double allocateSize = size;
                            if (starDefs > 1)
                                allocateSize = size / stars * proxy.DefUserSize.Value;

                            proxy.StarAllocated = true;
                            proxy.MinSize = allocateSize;
                            proxy.MeasureSize = allocateSize;
                            stars -= proxy.DefUserSize.Value;
                            size -= proxy.MinSize;
                            starDefs--;
                        }
                }
            }

            // Reset the star allocated field
            foreach (DefinitionProxy proxy in proxies)
                if (proxy.UserGridUnitType == GridUnitType.Star)
                    proxy.StarAllocated = false;
        }
 private void CalculateOffsetsAndTotals(DefinitionProxy[] proxies)
 {
     double totalMin = 0;
     double totalDesired = 0;
     foreach (DefinitionProxy proxy in proxies)
     {
         proxy.MinTotal = totalMin;
         proxy.DesiredTotal = totalDesired;
         totalMin += proxy.MinSize;
         totalDesired += proxy.DesiredSize;
     }
 }
        private double PreMeasure(double size, DefinitionProxy[] proxies)
        {
            double stars = 0.0;
            foreach (DefinitionProxy proxy in proxies)
                stars += proxy.PreMeasure(size);

            if (stars > 0.0)
                PreTargetStarDefinitions(size, proxies, stars);

            return stars;
        }
        private void BuildProxyRows()
        {
            // Is there a change to the row definitions?
            if (_rows.IsDirty)
            {
                // Do we need to recreate the proxy array?
                if ((_proxyRows == null) || (_proxyRows.Length != _rows.Count))
                {
                    // Always need at least one row
                    _proxyRows = new DefinitionProxy[Math.Max(1, _rows.Count)];
                }

                // Hook each row into the matching proxy
                for (int i = 0; i < _rows.Count; i++)
                    _proxyRows[i] = new DefinitionProxy(_rows[i]);

                // Our artifical row needs to point at a real row definition
                if (_columns.Count == 0)
                    _proxyRows[0] = new DefinitionProxy(new RowDefinition());
            }
        }