diff options
Diffstat (limited to 'Xamarin.Forms.Core/GridLengthTypeConverter.cs')
-rw-r--r-- | Xamarin.Forms.Core/GridLengthTypeConverter.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/GridLengthTypeConverter.cs b/Xamarin.Forms.Core/GridLengthTypeConverter.cs new file mode 100644 index 00000000..7c58b417 --- /dev/null +++ b/Xamarin.Forms.Core/GridLengthTypeConverter.cs @@ -0,0 +1,27 @@ +using System; +using System.Globalization; + +namespace Xamarin.Forms +{ + public class GridLengthTypeConverter : TypeConverter + { + public override object ConvertFromInvariantString(string value) + { + if (value == null) + return null; + + double length; + value = value.Trim(); + if (string.Compare(value, "auto", StringComparison.OrdinalIgnoreCase) == 0) + return GridLength.Auto; + if (string.Compare(value, "*", StringComparison.OrdinalIgnoreCase) == 0) + return new GridLength(1, GridUnitType.Star); + if (value.EndsWith("*", StringComparison.Ordinal) && double.TryParse(value.Substring(0, value.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture, out length)) + return new GridLength(length, GridUnitType.Star); + if (double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out length)) + return new GridLength(length); + + throw new FormatException(); + } + } +}
\ No newline at end of file |