Forum Xamarin.Forms

Set rectangle's values to AutoSize in XAML?

ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭
edited July 2017 in Xamarin.Forms


How do I set rectangle values to Auto in XAML?

Here's an example of what I want to achieve in XAML, the shorter syntax I can get the better.

var label = new Label();
AbsoluteLayout.SetLayoutBounds(label, new Rectangle(Point.Zero, new Size(AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)));


<!-- Doesn't compile -->
<Label AbsoluteLayout.LayoutBounds="0,0,Auto,Auto" />

Best Answer


  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭
    Accepted Answer

    Well the answer is change Auto to AutoSize.

  • James_EmkayJames_Emkay Member

    @ShimmyWeitzhandler said:
    Well the answer is change Auto to AutoSize.

    What should be the LayoutFlag if the size is set to AutoSize?

  • lucidBrotlucidBrot Member ✭✭

    Seems to me like the LayoutFlags must be set to Absolute in the relevant direction. Otherwise, it seems to not change anything for me.

    So, for a full-width view with autosized height, I use

Sign In or Register to comment.