Xamarin表格右对齐网格

时间:2016-11-12 15:26:02

标签: xamarin xamarin.forms

我使用的是7行3列的网格。我在第7行和第3列添加了一个按钮,如下所示:

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

问题是按钮始终位于中心。我似乎无法让它走到尽头。 这是结构

        
                                      
                                                                                                                                                                                                                                                                 

                <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>

我也试过

    View.HorizontalOptions="End"

1 个答案:

答案 0 :(得分:0)

将您的列定义归为此

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

按钮此代码没问题

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