private static GridLength GetValue(string valueName, GridLength defaultValue) { string str = GetValue(valueName, defaultValue.ToString()); try { return((GridLength) new GridLengthConverter().ConvertFromString(str)); } catch { return(defaultValue); } }
public void CtorDouble_Zero() { GridLength gl = new GridLength(0); Assert.AreEqual(0.0d, gl.Value, "Value"); Assert.AreEqual(GridUnitType.Pixel, gl.GridUnitType, "GridUnitType"); Assert.IsTrue(gl.IsAbsolute, "IsAbsolute"); Assert.IsFalse(gl.IsAuto, "IsAuto"); Assert.IsFalse(gl.IsStar, "IsStar"); Assert.AreEqual("0", gl.ToString(), "ToString"); }
public void CtorDoubleGridUnitType() { GridLength gl = new GridLength(42d, GridUnitType.Star); Assert.AreEqual(42d, gl.Value, "Value"); Assert.AreEqual(GridUnitType.Star, gl.GridUnitType, "GridUnitType"); Assert.IsFalse(gl.IsAbsolute, "IsAbsolute"); Assert.IsFalse(gl.IsAuto, "IsAuto"); Assert.IsTrue(gl.IsStar, "IsStar"); Assert.AreEqual("42*", gl.ToString(), "ToString"); }
static void CheckAuto(GridLength gl) { Assert.AreEqual(1.0d, gl.Value, "Value"); Assert.AreEqual(GridUnitType.Auto, gl.GridUnitType, "GridUnitType"); Assert.IsFalse(gl.IsAbsolute, "IsAbsolute"); Assert.IsTrue(gl.IsAuto, "IsAuto"); Assert.IsFalse(gl.IsStar, "IsStar"); Assert.AreEqual("Auto", gl.ToString(), "ToString"); Assert.IsFalse(gl.Equals(null), "Equals(null)"); Assert.IsTrue(gl.Equals(gl), "Equals(self)"); }
public void CtorDouble_Max() { GridLength gl = new GridLength(Double.MaxValue); Assert.AreEqual(Double.MaxValue, gl.Value, "Value"); Assert.AreEqual(GridUnitType.Pixel, gl.GridUnitType, "GridUnitType"); Assert.IsTrue(gl.IsAbsolute, "IsAbsolute"); Assert.IsFalse(gl.IsAuto, "IsAuto"); Assert.IsFalse(gl.IsStar, "IsStar"); // This fails on macos Assert.AreEqual(Double.MaxValue.ToString(), gl.ToString(), "ToString"); }
public async void ToString_AllCulture_Should_Pass(double d, GridUnitType type, string result) { List <CultureInfo> cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures).ToList(); GridLength length = new GridLength(d, type); foreach (var culture in cultureInfos) { await Task.Run(() => { CultureInfo.CurrentCulture = culture; Assert.Equal(result, length.ToString()); }); } }
public static String ParseGridLength(GridLength gridLength) { if (gridLength.IsAbsolute) { return(gridLength.Value.ToString(CultureInfo.InvariantCulture)); } if (gridLength.IsAuto) { return("Auto"); } var temp = gridLength.ToString().Replace("Star", "*").Replace(".*", "*"); if (temp.StartsWith("0")) { return(temp.Substring(1)); } return(temp); }
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}'"); } }
public void ToString_Invoke_ReturnsExpected(GridLength gridLength, string expected) { Assert.Equal(expected, gridLength.ToString()); }
private static void SetValue(string valueName, GridLength value) { SetValue(valueName, value.ToString()); }