Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Width/WidthRequest always returns -1

$
0
0

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?


Viewing all articles
Browse latest Browse all 58056

Trending Articles