Ejemplo n.º 1
0
        /// <summary>
        /// Gets initializer from string value.
        /// </summary>
        public override string GetInitializer(string stringValue)
        {
            var elementSizeConverter = new ElementSizeValueConverter();

            string[] valueList;
            valueList = stringValue.Split(',').ToArray();
            if (valueList.Length == 1)
            {
                return(String.Format(CultureInfo.InvariantCulture, "new ElementMargin({0})",
                                     elementSizeConverter.GetInitializer(valueList[0])));
            }
            else if (valueList.Length == 2)
            {
                return(String.Format(CultureInfo.InvariantCulture, "new ElementMargin({0}, {1})",
                                     elementSizeConverter.GetInitializer(valueList[0]),
                                     elementSizeConverter.GetInitializer(valueList[1])));
            }
            else if (valueList.Length == 3)
            {
                return(String.Format(CultureInfo.InvariantCulture, "new ElementMargin({0}, {1}, {2})",
                                     elementSizeConverter.GetInitializer(valueList[0]),
                                     elementSizeConverter.GetInitializer(valueList[1]),
                                     elementSizeConverter.GetInitializer(valueList[2])));
            }
            else if (valueList.Length == 4)
            {
                return(String.Format(CultureInfo.InvariantCulture, "new ElementMargin({0}, {1}, {2}, {3})",
                                     elementSizeConverter.GetInitializer(valueList[0]),
                                     elementSizeConverter.GetInitializer(valueList[1]),
                                     elementSizeConverter.GetInitializer(valueList[2]),
                                     elementSizeConverter.GetInitializer(valueList[3])));
            }

            throw new Exception(String.Format("Improperly formatted string."));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Interpolates value for type.
        /// </summary>
        public static ElementMargin Interpolator(ElementMargin from, ElementMargin to, float weight)
        {
            if (from == null || to == null)
            {
                return(weight < 1f ? from : to);
            }

            return(new ElementMargin(
                       ElementSizeValueConverter.Interpolator(from.Left, to.Left, weight),
                       ElementSizeValueConverter.Interpolator(from.Top, to.Top, weight),
                       ElementSizeValueConverter.Interpolator(from.Right, to.Right, weight),
                       ElementSizeValueConverter.Interpolator(from.Bottom, to.Bottom, weight)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts value from string.
        /// </summary>
        public override ColumnDefinitions Convert(string stringValue)
        {
            var floatValueConverter  = new FloatValueConverter();
            var elementSizeConverter = new ElementSizeValueConverter();

            string[] valueList         = stringValue.Split(',');
            var      columnDefinitions = new ColumnDefinitions();
            float    minWidth;
            float    maxWidth;

            for (int i = 0; i < valueList.Count(); ++i)
            {
                minWidth = 0;
                maxWidth = float.MaxValue;

                var defStr = valueList[i];
                if (valueList[i].Contains("["))
                {
                    var minMaxList = valueList[i].Split(MinMaxDelimiterChars, StringSplitOptions.RemoveEmptyEntries);
                    defStr = minMaxList[0];

                    if (minMaxList.Length == 2)
                    {
                        minWidth = floatValueConverter.Convert(minMaxList[1]);
                    }
                    else if (minMaxList.Length == 3)
                    {
                        minWidth = floatValueConverter.Convert(minMaxList[1]);
                        maxWidth = floatValueConverter.Convert(minMaxList[2]);
                    }
                    else
                    {
                        // improperly formatted string
                        throw new Exception("Improperly formatted ColumnDefinitions string. Supported examples: *,10,50,2* | 100[50-200], 10 | 10%,40%,50% | 100,100[10]");
                    }
                }

                var columnDefinition = new ColumnDefinition(elementSizeConverter.Convert(defStr), minWidth, maxWidth);
                columnDefinitions.Add(columnDefinition);
            }

            return(columnDefinitions);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets initializer from string value.
        /// </summary>
        public override string GetInitializer(string stringValue)
        {
            var floatValueConverter  = new FloatValueConverter();
            var elementSizeConverter = new ElementSizeValueConverter();
            var sb = new StringBuilder();

            string[] valueList = stringValue.Split(',');
            sb.Append("new ColumnDefinitions { ");
            for (int i = 0; i < valueList.Count(); ++i)
            {
                var    defStr    = valueList[i];
                string minMaxStr = string.Empty;
                if (valueList[i].Contains("["))
                {
                    var minMaxList = valueList[i].Split(MinMaxDelimiterChars, StringSplitOptions.RemoveEmptyEntries);
                    defStr = minMaxList[0];

                    if (minMaxList.Length == 2)
                    {
                        minMaxStr = String.Format(", {0}", floatValueConverter.GetInitializer(minMaxList[1]));
                    }
                    else if (minMaxList.Length == 3)
                    {
                        minMaxStr = String.Format(", {0}, {1}", floatValueConverter.GetInitializer(minMaxList[1]),
                                                  floatValueConverter.GetInitializer(minMaxList[2]));
                    }
                    else
                    {
                        // improperly formatted string
                        throw new Exception("Improperly formatted ColumnDefinitions string. Supported examples: *,10,50,2* | 100[50-200], 10 | 10%,40%,50% | 100,100[10]");
                    }
                }

                sb.AppendFormat("new ColumnDefinition({0}{1})", elementSizeConverter.GetInitializer(defStr), minMaxStr);
                if (i < valueList.Count() - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append("}");

            return(sb.ToString());
        }