Search code examples
.net-6.0maui.net-mauimaui-windows

Custom MAUI layout don't show any Control, but control have correct position and size,


I custom a layout name ConstraintLayout according to AbsoluteLayout in MAUI.

It like AbsoluteLayout have a LayoutManager class,i overrride Measure and ArrangeChildren method in this class.

It also have a ConstrainLayout class. public class ConstraintLayout : Layout, IConstraintLayout

Source Code at ConstraintLayout.Maui

I print control information, found control in layout have correct position and size, such as position of Entry at center of window. but nothing show at window.

I need set something at builder or Handler? i don't find doc about it.


Solution

  • I see that AbsoluteLayout works via a LayoutManager.

    Find AbsoluteLayout.cs. See its:

        protected override ILayoutManager CreateLayoutManager()
    

    Do similar, but find AbsoluteLayoutManager.cs, and make a similar ConstraintLayoutManager that uses your constraint logic. Then your method in ConstraintLayout will be:

    protected override ILayoutManager CreateLayoutManager()
    {
        return new ConstraintLayoutManager(this);
    }
    

    NOTE: Don't do my (now deleted) comment's ConstraintLayout : AbsoluteLayout .... Go back to your original ConstraintLayout : Layout, IConstraintLayout.