[英]Xamarin.Forms Custom ViewCell / ImageCell
I have changed my ImageCell to a custom ViewCell holding am image and three labels. 我将ImageCell更改为一个自定义ViewCell,其中包含图像和三个标签。
The ImageCell was loading images for cells just when they appear on the screen. 当ImageCell出现在屏幕上时,它们正在为它们加载图像。 My custom cell loads all images of all ViewCells during the initial load. 我的自定义单元会在初始加载期间加载所有ViewCell的所有图像。
How can I fix this, or how can I enhance my custom ViewCell to implement the same behaviour? 如何解决此问题,或者如何增强自定义ViewCell以实现相同的行为?
Thanks, Nikolai 谢谢,尼古拉
In your CustomViewCell you just need to override OnAppearing
and OnDisappearing
. 在CustomViewCell中,您只需要重写OnAppearing
和OnDisappearing
。
Both events are called while scrolling 滚动时调用两个事件
public class MyCell : ViewCell
{
protected override void OnAppearing()
{
base.OnAppearing();
// Do what happens on appeaering - load image
}
protected override void OnDisappearing()
{
base.OnDisappearing();
// Do what happens on disappeaering - unload image
}
public MyCell()
{
}
}
只要您没有在后台的任何地方加载它,如果您的列表视图设置为回收单元格,则在它们进入视图之前,它不应加载它们。
<ListView CachingStrategy="RecycleElement">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.