xamlxamarin.formsxamarin.ioslabelstacklayout

Xamarin StackLayout Horizontal and Vertical


<StackLayout>
    <Label HorizontalOptions="Center" VerticalOptions="Center" Text="Hello"/>
    <Slider/> 
 </StackLayout>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center" >
   <Label Text="Hello" />
    <Slider />
</StackLayout>

Output of above two codes are same can anyone explain the differece between specifying the vertical and horizontal options to stacklayout vs defining these properties at label ?


Solution

  • As jason mentioned , LayoutOptions only apply to the view/layout ,relative to its parent .

    In your case HorizontalOptions="Center" works for the Label and StackLayout , it is totally different .

    For the first scenario , Label locates in center of the outer stacklayout .

    For the second scenario, StackLayout locates in center of the outer layout(here I use StackLayout for test).

    Please check the following screenshot to clarify the differences.

    enter image description here