Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms Right align button in a Grid

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"
like image 899
jbassking10 Avatar asked Oct 30 '22 17:10

jbassking10


1 Answers

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"/>
like image 90
harsh patel Avatar answered Jan 02 '23 19:01

harsh patel