在我的 Xamarin.Forms 应用程序中,我有一个 ListView:
<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>
“ABC”应该出现的地方,只是标签背景的一条细红线。我没有看到实际的字母。我之前做过很多 ListView 都没问题,我不知道我在这里做错了什么?
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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句