I have the following logic for centering a view in the middle of a layout (which creates a background overlay in this case).
backdrop.Children.Add(popup,
Constraint.RelativeToParent(p => (Width / 2) - (popup.WidthRequest / 2)),
Constraint.RelativeToParent(p => (Height / 2) - (popup.HeightRequest / 2)),
Constraint.RelativeToParent(p => popup.WidthRequest),
Constraint.RelativeToParent(p => popup.HeightRequest));
The problem here is that I'm required to specify the dimentions of the popup
view in order to calculate its position. What I'd like to do is have its dimentions calculated automatically, based on the content. I could do the following
backdrop.Children.Add(popup, Constraint.Constant(0), Constraint.Constant(0));
but then the view isn't centered on the screen.
Is there a way to center it, without using the dimentions for the calculation? Or is there another solution that would allow centering based on the automatically calculated dimentions of the popup
view?