I use plain C# code and Xamarin.CommunityToolkit.Markup for my UI layout. I am trying to embrace declarative layout but struggle sometimes with the required syntax. My latest difficulty is with a RelativeLayout.
This works okay...
RelativeLayout layout = new RelativeLayout() { HorizontalOptions = LayoutOptions.FillAndExpand };
layout.Children.Add
(
new Grid(),
Constraint.Constant( 0.0 ),
Constraint.Constant( 0.0 ),
Constraint.RelativeToParent( ( r ) => r.Width ),
Constraint.RelativeToParent( ( r ) => r.Height )
);
... but is obviously not entirely declarative.
The closest I have got so far is...
LayoutOuter = new RelativeLayout()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
Children =
{
LayoutInner,
Constraint.Constant( 0.0 ),
Constraint.Constant( 0.0 ),
Constraint.RelativeToParent( ( r ) => r.Width ),
Constraint.RelativeToParent( ( r ) => r.Height )
}
};
...but I get an error along the lines of "The call is ambiguous between RelativeLayout.IRelativeList<T>.Add( T, Expression<Func<double>>, Expression<Func<double>>, Expression<Func<double>>, Expression<Func<double>>) and RelativeLayout.IRelativeList<T>.Add( T, Constraint, Constraint, Constraint, Constraint )"
How do I switch to fully declarative syntax?
