Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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;

            Constraint.RelativeToView(_relativeColumnOneUpperContainer, (p, s) => s.Bounds.Right + pctBarSpacing),
            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?


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

Sign In or Register to comment.