c# - ListView 项目文本在滚动时发生变化

标签 c# listview xamarin xamarin.forms listviewitem

我有一个 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>

这是关于我的问题的视频,在这个视频中你可以看到列表看起来不错但是当我开始滚动它时文本开始隐藏取消隐藏它的大小发生变化交叉图像变小或变大并删除列表项目所有文字消失

Gif video of my problem please watch this

最佳答案

这种重新呈现列表单元格的行为通常与 ListView 缓存策略有关。它定义了单元格的缓存方式,并尝试在加载大量数据时提高性能,但也可能影响正确的显示。尝试搞乱 CachingStrategy。根据过去的经验,将其设置为“RecycleElement”可以解决渲染问题。

另外,检查 this link有关 ListView 性能的更多信息。

关于c# - ListView 项目文本在滚动时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57035439/

相关文章:

c# - Moon APNS 的未知错误 P12 文件

c# - 如何在 VS2010 中创建自定义调试器可视化工具以可视化不可序列化的类?

java - Android项目中的错误

android - ListView 中的 EditText 没有它回收输入

ssl - X.iOS Cycle7 似乎破坏了 SSL

c# - 根据邻居标签设置标签位置

c# - 从 'IDbCommand.ExecuteNonQuery' 返回的值代表什么?

android - Android-有没有办法从ListView获取属性?

xamarin - 无法在 Xamarin Studio 中引用 PCL 库

visual-studio - 如何从Visual Studio为Xamarin Forms项目创建IPA文件