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 關注
- 136 瀏覽
添加回答
舉報