0

I'm working in a small piece of UI in Xamarin just a "card" with some labels and two buttons in the right side as a column. Here you can see my Xaml:

<Grid BackgroundColor="White" RowSpacing="0" ColumnSpacing="0" Margin="10,10,10,0">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="80"/>
    </Grid.ColumnDefinitions>

    <StackLayout Grid.Column="1" 
                 Spacing="0" 
                 BackgroundColor="PaleGoldenrod">
        <Button Text="OPEN" Margin="0" 
                VerticalOptions="FillAndExpand" 
                HeightRequest="70"/>
        <Button Text="RESET" Margin="0" 
                VerticalOptions="FillAndExpand" 
                HeightRequest="70"/>
    </StackLayout>

    <Label TextColor="Black" Margin="5">Relojes</Label>
    <Label  HorizontalTextAlignment="End" 
            TextColor="Black" 
            Margin="5">Sin Tocar</Label>
</grid>

And here you can see a picture of what I've got:

enter image description here

I want to remove the space between the two buttons so they are evenly spaced all around. I tried setting the bottom margin in the upper button as -2.5 and the upper margin of the bottom button as -2.5 and looks Ok but .. There must be a cleaner option. Any idea ??

javirs
  • 1,049
  • 26
  • 52

1 Answers1

0

Use Spacing in StackLayout to reduce space between controls. Here Spacing in minus.

<StackLayout  Grid.Column="1" 
Spacing="-8" 
BackgroundColor="PaleGoldenrod">
<Button Text="OPEN" Margin="0" 
VerticalOptions="FillAndExpand" 
HeightRequest="70"/>
<Button Text="RESET" Margin="0" 
VerticalOptions="FillAndExpand" 
HeightRequest="70"/>
</StackLayout>

enter image description here

R15
  • 13,982
  • 14
  • 97
  • 173
  • this is really how it is meant to be? To get zero spacing you have to use -"some unknown value" ??? – javirs Oct 05 '18 at 09:17
  • I don't think people creating xamarin decided: "and the to get zero spacing they will have to figure out a magic number and use it as negative spacing. – javirs Oct 05 '18 at 09:20
  • As I know, according to xamarin default spacing value of a stacklayout = 6. – R15 Oct 05 '18 at 09:24
  • this should be the value if you do nothing. and when set the spacing to zero .. is surprising it is not zero. Isnt it ? The default value for horizontalOption is properly overwriten. You don't need to do "-defaultvalue" – javirs Oct 05 '18 at 09:50
  • Yeah it is surprising. But Microsoft never do anything w/o reason. – R15 Oct 05 '18 at 09:53
  • hehe this is exactly why I'm pointing it out. There is somehting we are not getting right here. And we need someone to point it out for us :) – javirs Oct 05 '18 at 10:01
  • I really don't thing this is the solution. In my question I already stated that doing negative values in the margins provided the desired visuals. But is not the style of coding I'm looking for. Sorry – javirs Oct 05 '18 at 10:42