示例#1
0
        public static ColumnDefinitions FromString(String val)
        {
            var coll = new ColumnDefinitions();

            if (val.StartsWith("Repeat"))
            {
                var regex = new Regex(@"^Repeat\((.+)\)$");
                var match = regex.Match(val.Trim());
                if (match.Groups.Count < 2)
                {
                    throw new XamlException($"Invalid repeat value '{val}'");
                }

                var w  = GridLength.FromString(match.Groups[1].Value.Trim());
                var cd = new ColumnDefinition()
                {
                    Width = new GridLength($"repeat(auto-fit, {w})")
                };
                coll.Add(cd);
            }
            else
            {
                foreach (var row in val.Split(','))
                {
                    var cd = new ColumnDefinition()
                    {
                        Width = GridLength.FromString(row.Trim())
                    };
                    coll.Add(cd);
                }
            }
            return(coll);
        }
示例#2
0
 public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
 {
     if (value == null)
     {
         return(null);
     }
     if (value is String)
     {
         String strVal = value.ToString();
         return(GridLength.FromString(strVal));
     }
     throw new XamlException($"Invalid length value '{value}'");
 }
示例#3
0
        public static RowDefinitions FromString(String val)
        {
            var coll = new RowDefinitions();

            foreach (var row in val.Split(','))
            {
                var rd = new RowDefinition
                {
                    Height = GridLength.FromString(row.Trim())
                };
                coll.Add(rd);
            }
            return(coll);
        }
示例#4
0
        public static ColumnDefinitions FromString(String val)
        {
            var coll = new ColumnDefinitions();

            foreach (var row in val.Split(','))
            {
                var cd = new ColumnDefinition
                {
                    Width = GridLength.FromString(row.Trim())
                };
                coll.Add(cd);
            }
            return(coll);
        }
示例#5
0
        public void When_Color_Thickness_GridLength_As_String()
        {
            var s = GetContent(nameof(When_Color_Thickness_GridLength_As_String));
            var r = Windows.UI.Xaml.Markup.XamlReader.Load(s) as ContentControl;

            Assert.AreEqual(Windows.UI.Colors.Red, r.Resources["Color01"]);
            Assert.AreEqual(Windows.UI.Colors.Blue, (r.Resources["scb01"] as SolidColorBrush).Color);
            Assert.AreEqual(new Thickness(42), r.Resources["thickness"]);
            Assert.AreEqual(new CornerRadius(42), r.Resources["cornerRadius"]);
            Assert.AreEqual("TestFamily", (r.Resources["fontFamily"] as FontFamily).Source);
            Assert.AreEqual(GridLength.FromString("42"), r.Resources["gridLength"]);
            Assert.AreEqual(Windows.UI.Xaml.Media.Animation.KeyTime.FromTimeSpan(TimeSpan.Parse("1:2:3")), r.Resources["keyTime"]);
            Assert.AreEqual(new Duration(TimeSpan.Parse("1:2:3")), r.Resources["duration"]);
            Assert.AreEqual(Matrix.Identity, r.Resources["matrix"]);
            Assert.AreEqual(Windows.UI.Text.FontWeights.Bold, r.Resources["fontWeight"]);

            Assert.AreEqual(Windows.UI.Colors.Red, ((r.Content as Grid)?.Background as SolidColorBrush).Color);
        }
示例#6
0
        public static GridLength FromString(String strVal)
        {
            Double dblVal = 0;

            if (strVal == "Auto")
            {
                return(new GridLength("auto"));
            }
            else if (strVal.StartsWith("MinMax"))
            {
                var re    = new Regex(@"MinMax\(([\w\.]+[%\*\.]?);([\w\.]+[%\*\.]?)\)");
                var match = re.Match(strVal.Replace(" ", String.Empty));
                if (match.Groups.Count != 3)
                {
                    throw new XamlException($"Invalid grid length value '{strVal}'");
                }
                GridLength gl1 = GridLength.FromString(match.Groups[1].Value);
                GridLength gl2 = GridLength.FromString(match.Groups[2].Value);
                return(new GridLength($"minmax({gl1.ToString()},{gl2.ToString()})"));
            }
            else if (Length.IsValidLength(strVal))
            {
                return new GridLength()
                       {
                           Value = strVal
                       }
            }
            ;
            if (strVal.EndsWith("*"))
            {
                return(new GridLength(strVal.Trim().Replace("*", "fr")));
            }
            else if (Double.TryParse(strVal, out dblVal))
            {
                return(new GridLength(strVal + "px"));
            }
            throw new XamlException($"Invalid grid length value '{strVal}'");
        }
    }