3 回答
TA贡献2019条经验 获得超9个赞
这种重新渲染列表单元格的行为通常与ListView缓存策略有关。它定义了单元格的缓存方式,并尝试在加载大量数据时提高性能,但也可能会影响正确的显示。尝试搞乱CachingStrategy. 根据过去的经验,将其设置为“RecycleElement”可以解决渲染问题。
TA贡献1851条经验 获得超3个赞
尝试这个
<ListView
x:Name="list"
SelectionMode="None"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
SeparatorVisibility="None"
HasUnevenRows="True"
BackgroundColor="Transparent"
CachingStrategy="RetainElement"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame Padding="10" Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition Height="Auto"
/>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Orientation="Horizontal" HorizontalOptions="FillAndExpand" >
<Label
Text="{Binding Note}"
HorizontalOptions="StartAndExpand"
TextColor="Black"
FontSize="Small"
FontFamily="
{StaticResource BoldFont}"
FontAttributes="Bold">
</Label>
<ImageButton
HorizontalOptions="EndAndExpand"
WidthRequest="22"
HeightRequest="22"
Padding="6"
Margin="0,0,0,0"
Clicked="btndelete"
AbsoluteLayout.LayoutBounds="0,0,1,1"
BackgroundColor="Transparent"
Source="close.png">
</ImageButton>
</StackLayout>
<StackLayout Grid.Row="1" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Label
Text="{Binding
NOfQuestions}"
HorizontalOptions="StartAndExpand"
FontSize="12"
FontFamily="
{StaticResource Regular}"
TextColor="White">
</Label>
<Label
Margin="15,0,0,0"
Text="{Binding
NOfDigits}"
HorizontalOptions="CenterAndExpand"
FontSize="12"
FontFamily="
{StaticResource Regular}"
TextColor="White">
</Label>
</StackLayout>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
TA贡献2041条经验 获得超4个赞
当您在 a 中有自定义单元格时,ListView建议使用CachingStrategy
ListView是显示数据的强大视图,但它有一些局限性。使用自定义单元格时,滚动性能可能会受到影响,特别是当它们包含深度嵌套的视图层次结构或使用需要复杂测量的某些布局时。
Xamarin.Forms 的 XAML 为与缓存策略参数对应的不存在的属性提供 XAML 属性:
<ListView CachingStrategy="RecycleElement" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- ... -->
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
- 3 回答
- 0 关注
- 205 浏览
添加回答
举报
