John Livermore
John Livermore

Reputation: 31313

Xamarin Forms checkbox - change default padding

I have XF checkbox that displays with too much right padding. Here is what it looks like in iOS (BackgroundColor="Red" to highlight the padding issue).

enter image description here

How can I remove the right padding to match the padding on the left? Or is this even possible?

XAML

                    <StackLayout Grid.Row="2" Grid.Column="1" 
                                 Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding HasEnd}"
                                  Margin="0"
                                  BackgroundColor="Red" />
                        <Label Style="{StaticResource FormLabel}"
                               Margin="0"
                               Text="Has Ending Date" />
                    </StackLayout>

Upvotes: 1

Views: 1477

Answers (1)

Ricardo Dias Morais
Ricardo Dias Morais

Reputation: 2087

There is 2 ways of doing this with workarounds.

Overlapping the Label and the Checkbox with an Grid and give the Label the correct margin needed like this:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <CheckBox Grid.Row="0" Grid.Column="0" IsChecked="{Binding HasEnd}"
                         Margin="0"
                         BackgroundColor="Red" />
    <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource FormLabel}"
                  Margin="10,0,0,0" <- The Margin needed
                  Text="Has Ending Date" />            
</Grid>

Not a graceful one, but you can give negative Margin to the Label

<Label Style="{StaticResource FormLabel}"
              Margin="-10,0,0,0"
              Text="Has Ending Date" />

You can also try the Input Kit Nugget package if you want more controll over your inputs.

Upvotes: 4

Related Questions