diff --git a/src/Core/src/Converters/CornerRadiusTypeConverter.cs b/src/Core/src/Converters/CornerRadiusTypeConverter.cs index e41fb9952cc3..874828d84be0 100644 --- a/src/Core/src/Converters/CornerRadiusTypeConverter.cs +++ b/src/Core/src/Converters/CornerRadiusTypeConverter.cs @@ -4,17 +4,22 @@ namespace Microsoft.Maui.Converters { + /// public class CornerRadiusTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) => destinationType == typeof(string); + /// public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value) { var strValue = value?.ToString(); + if (strValue != null) { value = strValue.Trim(); @@ -61,11 +66,14 @@ public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(CornerRadius)}"); } + /// public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (value is not CornerRadius cr) throw new NotSupportedException(); - return $"{cr.TopLeft.ToString(CultureInfo.InvariantCulture)}, {cr.TopRight.ToString(CultureInfo.InvariantCulture)}, {cr.BottomLeft.ToString(CultureInfo.InvariantCulture)}, {cr.BottomRight.ToString(CultureInfo.InvariantCulture)}"; + + return $"{cr.TopLeft.ToString(CultureInfo.InvariantCulture)}, {cr.TopRight.ToString(CultureInfo.InvariantCulture)}, " + + $"{cr.BottomLeft.ToString(CultureInfo.InvariantCulture)}, {cr.BottomRight.ToString(CultureInfo.InvariantCulture)}"; } } diff --git a/src/Core/src/Converters/EasingTypeConverter.cs b/src/Core/src/Converters/EasingTypeConverter.cs index c8416e280b45..ac8ab53d276a 100644 --- a/src/Core/src/Converters/EasingTypeConverter.cs +++ b/src/Core/src/Converters/EasingTypeConverter.cs @@ -9,14 +9,18 @@ namespace Microsoft.Maui.Converters { + /// public class EasingTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => destinationType == typeof(string); + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -26,6 +30,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c strValue = strValue?.Trim() ?? ""; var parts = strValue.Split('.'); + if (parts.Length == 2 && parts[0] == nameof(Easing)) strValue = parts[parts.Length - 1]; @@ -64,6 +69,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(Easing)}"); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not Easing easing) @@ -91,28 +97,32 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul return nameof(SpringIn); if (easing == SpringOut) return nameof(SpringOut); + throw new NotSupportedException(); } + /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true; + /// public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => false; + /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) => new(new[] { - "Linear", - "SinOut", - "SinIn", - "SinInOut", - "CubicIn", - "CubicOut", - "CubicInOut", - "BounceOut", - "BounceIn", - "SpringIn", - "SpringOut" + "Linear", + "SinOut", + "SinIn", + "SinInOut", + "CubicIn", + "CubicOut", + "CubicInOut", + "BounceOut", + "BounceIn", + "SpringIn", + "SpringOut" }); } -} +} \ No newline at end of file diff --git a/src/Core/src/Converters/FlexEnumsConverters.cs b/src/Core/src/Converters/FlexEnumsConverters.cs index 5ffec8389665..1c6befafbff5 100644 --- a/src/Core/src/Converters/FlexEnumsConverters.cs +++ b/src/Core/src/Converters/FlexEnumsConverters.cs @@ -2,19 +2,22 @@ using System.ComponentModel; using System.Globalization; using Microsoft.Maui.Layouts; -using Flex = Microsoft.Maui.Layouts.Flex; #nullable disable namespace Microsoft.Maui.Converters { + /// public class FlexJustifyTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -32,25 +35,32 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (strValue.Equals("space-around", StringComparison.OrdinalIgnoreCase)) return FlexJustify.SpaceAround; } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexJustify))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexJustify fj) throw new NotSupportedException(); + return fj.ToString(); } } + /// public class FlexDirectionTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -64,25 +74,32 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (strValue.Equals("column-reverse", StringComparison.OrdinalIgnoreCase)) return FlexDirection.ColumnReverse; } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexDirection))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexDirection fd) throw new NotSupportedException(); + return fd.ToString(); } } + /// public class FlexAlignContentTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -100,25 +117,32 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (strValue.Equals("space-around", StringComparison.OrdinalIgnoreCase)) return FlexAlignContent.SpaceAround; } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexAlignContent))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexAlignContent fac) throw new NotSupportedException(); + return fac.ToString(); } } + /// public class FlexAlignItemsTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -132,25 +156,32 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (strValue.Equals("flex-end", StringComparison.OrdinalIgnoreCase)) return FlexAlignItems.End; } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexAlignItems))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexAlignItems fai) throw new NotSupportedException(); + return fai.ToString(); } } + /// public class FlexAlignSelfTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -164,25 +195,32 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (strValue.Equals("flex-end", StringComparison.OrdinalIgnoreCase)) return FlexAlignSelf.End; } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexAlignSelf))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexAlignSelf fes) throw new NotSupportedException(); + return fes.ToString(); } } + /// public class FlexWrapTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); @@ -194,31 +232,40 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (strValue.Equals("wrap-reverse", StringComparison.OrdinalIgnoreCase)) return FlexWrap.Reverse; } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexWrap))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexWrap fw) throw new NotSupportedException(); + return fw.ToString(); } } + /// public class FlexBasisTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => true; + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); + if (strValue != null) { strValue = strValue.Trim(); + if (strValue.Equals("auto", StringComparison.OrdinalIgnoreCase)) return FlexBasis.Auto; if (strValue.EndsWith("%", StringComparison.OrdinalIgnoreCase) && float.TryParse(strValue.Substring(0, strValue.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture, out float relflex)) @@ -226,17 +273,21 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c if (float.TryParse(strValue, NumberStyles.Number, CultureInfo.InvariantCulture, out float flex)) return new FlexBasis(flex); } + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(FlexBasis))); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not FlexBasis basis) throw new NotSupportedException(); + if (basis.IsAuto) return "auto"; if (basis.IsRelative) return $"{(basis.Length * 100).ToString(CultureInfo.InvariantCulture)}%"; + return $"{basis.Length.ToString(CultureInfo.InvariantCulture)}"; } } diff --git a/src/Core/src/Converters/KeyboardTypeConverter.cs b/src/Core/src/Converters/KeyboardTypeConverter.cs index d7d4555266ba..2ad987f3991a 100644 --- a/src/Core/src/Converters/KeyboardTypeConverter.cs +++ b/src/Core/src/Converters/KeyboardTypeConverter.cs @@ -6,20 +6,26 @@ namespace Microsoft.Maui.Converters { + /// public class KeyboardTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) => destinationType == typeof(string); + /// public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value) { var strValue = value?.ToString(); + if (strValue != null) { string[] parts = strValue.Split('.'); + if (parts != null && parts.Length == 1 || (parts != null && parts.Length == 2 && parts[0] == "Keyboard")) { var kbType = typeof(Keyboard); @@ -38,10 +44,12 @@ public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(Keyboard))); } + /// public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) { if (!(value is Keyboard keyboard)) throw new NotSupportedException(); + if (keyboard == Keyboard.Plain) return nameof(Keyboard.Plain); if (keyboard == Keyboard.Chat) @@ -58,6 +66,7 @@ public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? c return nameof(Keyboard.Text); if (keyboard == Keyboard.Url) return nameof(Keyboard.Url); + throw new NotSupportedException(); } } diff --git a/src/Core/src/Converters/ThicknessTypeConverter.cs b/src/Core/src/Converters/ThicknessTypeConverter.cs index ae3fdb0616bd..8cf71e512c90 100644 --- a/src/Core/src/Converters/ThicknessTypeConverter.cs +++ b/src/Core/src/Converters/ThicknessTypeConverter.cs @@ -6,20 +6,26 @@ namespace Microsoft.Maui.Converters { + /// public class ThicknessTypeConverter : TypeConverter { + /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => sourceType == typeof(string); + /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) => destinationType == typeof(string); + /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var strValue = value?.ToString(); + if (strValue != null) { strValue = strValue.Trim(); + if (strValue.IndexOf(",", StringComparison.Ordinal) != -1) { //Xaml var thickness = strValue.Split(','); @@ -74,11 +80,14 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(Thickness)}"); } + /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is not Thickness t) throw new NotSupportedException(); - return $"{t.Left.ToString(CultureInfo.InvariantCulture)}, {t.Top.ToString(CultureInfo.InvariantCulture)}, {t.Right.ToString(CultureInfo.InvariantCulture)}, {t.Bottom.ToString(CultureInfo.InvariantCulture)}"; + + return $"{t.Left.ToString(CultureInfo.InvariantCulture)}, {t.Top.ToString(CultureInfo.InvariantCulture)}, " + + $"{t.Right.ToString(CultureInfo.InvariantCulture)}, {t.Bottom.ToString(CultureInfo.InvariantCulture)}"; } } } \ No newline at end of file