3 回答

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個贊
這種重新渲染列表單元格的行為通常與ListView
緩存策略有關(guān)。它定義了單元格的緩存方式,并嘗試在加載大量數(shù)據(jù)時提高性能,但也可能會影響正確的顯示。嘗試搞亂CachingStrategy
.?根據(jù)過去的經(jīng)驗(yàn),將其設(shè)置為“RecycleElement”可以解決渲染問題。

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超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貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個贊
當(dāng)您在 a 中有自定義單元格時,ListView建議使用CachingStrategy
ListView是顯示數(shù)據(jù)的強(qiáng)大視圖,但它有一些局限性。使用自定義單元格時,滾動性能可能會受到影響,特別是當(dāng)它們包含深度嵌套的視圖層次結(jié)構(gòu)或使用需要復(fù)雜測量的某些布局時。
Xamarin.Forms 的 XAML 為與緩存策略參數(shù)對應(yīng)的不存在的屬性提供 XAML 屬性:
<ListView CachingStrategy="RecycleElement" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- ... -->
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
- 3 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)