Xamarin generates relative position of stacklayout position at bottom

I would like to position the Stacklayout from the bottom on top of the image using relative layout using Xamarin forms using only xaml. The Xaml looks something like this.

<RelativeLayout>
    <Image />
    <StackLayout Orientation="Horizontal">
        <Label Text="Dark Mode" />
        <Switch />
        <Label Text="Light Mode" />
    </StackLayout>
</RelativeLayout>

      

What X and Y constraints should my StackLayout have so that it sits on top of the image and at the bottom of it. Also added an image that describes the expected result.

Expected: RelativeLayout

I tried to provide RelativeLayout.XConstraints and RelativeLayout.YConstraints for both the image and stacklayout, but couldn't figure out what values ​​to use to get the desired result.

+3


source to share


1 answer


You can have a StackLayout in the whole picture, and in it another StackLayout, which will be located at the bottom:

<RelativeLayout>
  <Image Aspect="AspectFill"
         RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
         RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"/>
  <StackLayout
         RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
         RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}">
      <StackLayout Orientation="Horizontal" VerticalOptions="EndAndExpand" HorizontalOptions="Center">
          <Label Text="Dark Mode" />
          <Switch />
          <Label Text="Light Mode" />
      <StackLayout>
  </StackLayout>

      



+3


source







All Articles