5
votes

I'm using a Grid with 7 rows and 3 columns. I added a button to the 7th row and 3rd column like this:

<Button Grid.Row="6" Grid.Column="2" HorizontalOptions="End"/>

The problem is the button is always in the center. I can't seem to get it to go to the end. Here's the structure



                <Image Aspect="AspectFit" HeightRequest="60" Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"  Source="{Binding ProdImg}" />
                <Label Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" TextColor="White" FontSize="22" Text="{Binding UserName}"/>
                <Label HorizontalOptions="End" Grid.Row="0" Grid.Column="2" TextColor="#b1fc03" FontSize="25" Text ="{Binding Sales, StringFormat='{0:#,#.}'}"/>                                
                <Label Grid.Row="1" Grid.Column="1" HorizontalOptions="Start" TextColor="White" FontSize="10" Text="{Binding LastSale, StringFormat='{0:dd-MMM-yyyy}'}"/>
                <Label HorizontalOptions="End" Grid.Row="1" Grid.Column="2" TextColor="White" FontSize="10" Text="{Binding ProdName}"/>

                <Button x:Name="TryNowBtn" HorizontalOptions="End" Image="try-now.png" Grid.Row="2" Grid.Column="2"></Button>                      
              </Grid>                
            </StackLayout>
          <Image Aspect="AspectFit" Source="separator-line.png"/>
          </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

I also tried

    View.HorizontalOptions="End"
1
Can you paste the rest of the XAML for the <Grid>? It ends at the opening <Grid> tag right now.DavidS
I added the rest of the xamljbassking10
can you show how you define the grid height weight.. those label and image are irrelevant actually..Lee

1 Answers

3
votes

chagne your column definition to this

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

for button this code is ok

<Button Grid.Row="6" Grid.Column="2" HorizontalOptions="End"/>