Align label and switch in xamarin forms

2.6k views Asked by At

I want to align the label and switch in xamarin forms. I used grid but the label and switch wont align (see image for reference)

enter image description here

Here is my XAML:

<Grid>
      <Label Grid.Row="0" Grid.Column="0" Text="Rekorida" StyleClass="lbl-fieldform">
            <Label.FontFamily>
                   <OnPlatform x:TypeArguments="x:String">
                        <On Platform="Android" Value="HelveticaNeueLTPro-Lt.otf#HelveticaNeueLTPro-Lt"/>
                   </OnPlatform>
            </Label.FontFamily>
       </Label>
       <Switch Grid.Row="0" Grid.Column="1" VerticalOptions="Start" x:Name="swRekorida" Toggled="Activity_Toggled"/>
</Grid>
1

There are 1 answers

0
AudioBubble On

Use this:

<Grid VerticalOptions="Center">
    <Grid.RowDefinitions>
       <RowDefinition Height="40"/>
    </Grid.RowDefinitions>
    <Label VerticalTextAlignment="Center" Grid.Row="0" Grid.Column="0" Text="Rekorida" StyleClass="lbl-fieldform">
       <Label.FontFamily>
           <OnPlatform x:TypeArguments="x:String">
               <On Platform="Android" Value="HelveticaNeueLTPro-Lt.otf#HelveticaNeueLTPro-Lt"/>
            </OnPlatform>
        </Label.FontFamily>
     </Label>
     <Switch Grid.Row="0" Grid.Column="1" VerticalOptions="Center" x:Name="swRekorida" Toggled="Activity_Toggled"/>
</Grid>