我有一个 ListView ,我在其中绑定(bind)多个数据,如标签和图像,并且我在我的框架中有该列表,所以当列表大小大于 10 个项目时,然后在滚动时我的图像会自行调整大小和标签文本开始隐藏取消隐藏。
这是我的 xaml:
<ListView
x:Name="list"
SelectionMode="None"
SeparatorVisibility="None"
HasUnevenRows="True"
IsVisible="False"
BackgroundColor="Transparent"
ItemTapped="List_ItemTapped"
CachingStrategy="RetainElement"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame Padding="10" Margin="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition Height="*"
/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="Auto" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
Text="{Binding Note}"
HorizontalOptions="Start"
TextColor="Black"
FontSize="Small"
FontFamily="
{StaticResource BoldFont}"
FontAttributes="Bold">
</Label>
<ImageButton
Grid.Row="0"
Grid.Column="1"
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>
<Label
Grid.Row="1"
Grid.Column="0"
Text="{Binding
NOfQuestions}"
FontSize="12"
FontFamily="
{StaticResource Regular}"
TextColor="White">
</Label>
<Label
Grid.Row="1"
Grid.Column="0"
Margin="15,0,0,0"
Text="{Binding
NOfDigits}"
FontSize="12"
FontFamily="
{StaticResource Regular}"
TextColor="White">
</Label>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是关于我的问题的视频,在这个视频中你可以看到列表看起来不错但是当我开始滚动它时文本开始隐藏取消隐藏它的大小发生变化交叉图像变小或变大并删除列表项目所有文字消失
最佳答案
这种重新呈现列表单元格的行为通常与 ListView
缓存策略有关。它定义了单元格的缓存方式,并尝试在加载大量数据时提高性能,但也可能影响正确的显示。尝试搞乱 CachingStrategy
。根据过去的经验,将其设置为“RecycleElement”可以解决渲染问题。
另外,检查 this link有关 ListView 性能的更多信息。
关于c# - ListView 项目文本在滚动时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57035439/