private static string GetValueExpression(object declaredDefaultValue, List <UsingStatement> usings) { if (declaredDefaultValue is null) { throw new ArgumentNullException(nameof(declaredDefaultValue)); } return(declaredDefaultValue switch { bool boolValue => boolValue ? "true" : "false", int intValue => GetIntValueExpression(intValue), float floatValue => floatValue.ToString("F", CultureInfo.InvariantCulture) + "f", // "Fixed-Point": https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-fixed-point-f-format-specifier double doubleValue => doubleValue.ToString("F", CultureInfo.InvariantCulture), // "Fixed-Point": https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-fixed-point-f-format-specifier Enum enumValue => GetTypeNameAndAddNamespace(enumValue.GetType(), usings) + "." + Enum.GetName(enumValue.GetType(), declaredDefaultValue), XF.GridLength gridLengthValue => GetGridLengthValueExpression(gridLengthValue, usings), XF.LayoutOptions layoutOptionsValue => GetLayoutOptionsValueExpression(layoutOptionsValue, usings), string stringValue => $@"""{stringValue}""", // TODO: More types here _ => null, });
private static string GetValueExpression(object declaredDefaultValue, List <UsingStatement> usings) { if (declaredDefaultValue is null) { throw new ArgumentNullException(nameof(declaredDefaultValue)); } return(declaredDefaultValue switch { bool boolValue => boolValue ? "true" : "false", int intValue => GetIntValueExpression(intValue), float floatValue => floatValue.ToString("F", CultureInfo.InvariantCulture) + "f", // "Fixed-Point": https://docs.microsoft.com/dotnet/standard/base-types/standard-numeric-format-strings#the-fixed-point-f-format-specifier double doubleValue => doubleValue.ToString("F", CultureInfo.InvariantCulture), // "Fixed-Point": https://docs.microsoft.com/dotnet/standard/base-types/standard-numeric-format-strings#the-fixed-point-f-format-specifier Enum enumValue => GetTypeNameAndAddNamespace(enumValue.GetType(), usings) + "." + Enum.GetName(enumValue.GetType(), declaredDefaultValue), XF.GridLength gridLengthValue => GetGridLengthValueExpression(gridLengthValue, usings), XF.LayoutOptions layoutOptionsValue => GetLayoutOptionsValueExpression(layoutOptionsValue, usings), string stringValue => $@"""{stringValue}""", DateTime dateTimeValue => $"global::System.DateTime.Parse(\"{dateTimeValue.ToString("o", CultureInfo.InvariantCulture)}\", null, global::System.Globalization.DateTimeStyles.RoundtripKind)", // "Round-trip": https://docs.microsoft.com/dotnet/standard/base-types/how-to-round-trip-date-and-time-values TimeSpan timeSpanValue => timeSpanValue.Ticks.ToString(CultureInfo.InvariantCulture), // TODO: More types here _ => null, });
private static TableRow CreateRow (Context context, View leftTextView, View rightTextView, GridLength leftColumnWidth, GridLength rightColumnWidth) { var tableRow = new TableRow (context); var linearLayout = new LinearLayout (context) { WeightSum = (float)1.0 }; //This is a little counter intuitive, but the Left Text View needs to be set to the Right Column Width var leftTextViewLayout = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) { Weight = (float)rightColumnWidth.Value }; leftTextView.LayoutParameters = leftTextViewLayout; linearLayout.AddView (leftTextView); var rightTextViewLayout = new LinearLayout.LayoutParams (ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) { Weight = (float)leftColumnWidth.Value }; rightTextView.LayoutParameters = rightTextViewLayout; linearLayout.AddView (rightTextView); tableRow.AddView (linearLayout); return tableRow; }
bool Equals(GridLength other) { return GridUnitType == other.GridUnitType && Math.Abs(Value - other.Value) < double.Epsilon; }
internal override void ComputeConstraintForView(View view) { LayoutOptions vOptions = view.VerticalOptions; LayoutOptions hOptions = view.HorizontalOptions; var result = LayoutConstraint.None; if (_rows == null || _columns == null) { EnsureRowsColumnsInitialized(); } if (vOptions.Alignment == LayoutAlignment.Fill) { int row = GetRow(view); int rowSpan = GetRowSpan(view); List <RowDefinition> rowDefinitions = _rows; var canFix = true; for (int i = row; i < row + rowSpan && i < rowDefinitions.Count; i++) { GridLength height = rowDefinitions[i].Height; if (height.IsAuto) { canFix = false; break; } if ((Constraint & LayoutConstraint.VerticallyFixed) == 0 && height.IsStar) { canFix = false; break; } } if (canFix) { result |= LayoutConstraint.VerticallyFixed; } } if (hOptions.Alignment == LayoutAlignment.Fill) { int col = GetColumn(view); int colSpan = GetColumnSpan(view); List <ColumnDefinition> columnDefinitions = _columns; var canFix = true; for (int i = col; i < col + colSpan && i < columnDefinitions.Count; i++) { GridLength width = columnDefinitions[i].Width; if (width.IsAuto) { canFix = false; break; } if ((Constraint & LayoutConstraint.HorizontallyFixed) == 0 && width.IsStar) { canFix = false; break; } } if (canFix) { result |= LayoutConstraint.HorizontallyFixed; } } view.ComputedConstraint = result; }