代码之家  ›  专栏  ›  技术社区  ›  Drake

ListView未正确显示标签

  •  0
  • Drake  · 技术社区  · 6 年前

    在我的Xamarin.Forms应用程序中,我有一个列表视图:

    <ListView ItemsSource="{Binding MyItems}"
                      Grid.Row="1"
                      Margin="0,20,0,0">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Label Text="ABC" FontSize="Large" TextColor="Black" BackgroundColor="Red" Margin="20" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
    </ListView>
    

    1 回复  |  直到 6 年前
        1
  •  2
  •   Tom    6 年前

    ViewCell

    为简单起见,您可以实现 StackLayout :

    <ListView 
        ItemsSource="{Binding MyItems}"
        Grid.Row="1"
        Margin="0,20,0,0>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout 
                        HorizontalOptions="FillAndExpand"
                        Margin="0"
                        Padding="0"
                        Spacing="0"
                        VerticalOptions="Fill">
                        <Label 
                            BackgroundColor="Red"
                            FontSize="Large"
                            HorizontalOptions="FillAndExpand"
                            HorizontalTextAlignment="Center"
                            Margin="20" 
                            Text="ABC" 
                            TextColor="Black"  
                            VerticalOptions="FillAndExpand"
                            VerticalTextAlignment="Center"/>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>