Forum Xamarin.Forms

Creating a custom Layout,View> with horizontal and vertical layout options

BrunoVTBrunoVT BEUniversity ✭✭

Hello,

I want to create a layout that positions views on top of each other(I don't want to use a grid). I got it partially working but it does not work when I want to center a view inside my layout. It always ends up in the top left corner. How can I fix this?

public class CustomStackLayout : Layout<View>
{
    protected override void LayoutChildren(double x, double y, double width, double height)
    {
        if (Children.Count > 0)
        {
            foreach (var child in Children)
            {
                var request = child.Measure(width, height, MeasureFlags.IncludeMargins);

                var bounds = new Rectangle(x, y, request.Request.Width, request.Request.Height);

                LayoutChildIntoBoundingRegion(child, bounds);
            }
        }
    }
}
Sign In or Register to comment.