Width/WidthRequest always returns -1

DustinDittmer.8607DustinDittmer.8607 USMember
edited March 2015 in Xamarin.Forms

I've got a control which is essentially a relativelayout which contains 6 more relativelayouts. I'm attempting to set the width of the subviews to fill the parent container.

However, when I attempt to set the widths of the subviews like this:

        const double pctBarWidth = 0.16;
        const double pctBarSpacing = 0.008;

        relativeUpperContainer.Children.Add(_relativeColumnTwoUpperContainer,
            Constraint.RelativeToView(_relativeColumnOneUpperContainer, (p, s) => s.Bounds.Right + pctBarSpacing),
            Constraint.Constant(0),
            Constraint.RelativeToParent(p => p.Bounds.Width * pctBarWidth),
            Constraint.RelativeToParent(p => p.Bounds.Height));

The columns are always 16px wide, not 16% wide, because when I debug the parent container width it returns -1.

I've also swapped the RelativeToParent constraint out with Constraint.Constant with a reference to the ParentView.Bounds.Width but the results are the same.

How can I get the width of my parent container so I can dynamically size its subviews correctly?

Posts

  • DustinDittmer.8607DustinDittmer.8607 USMember

    Thanks for the reply @DavidDancy, right on all accounts.

Sign In or Register to comment.