Xamarin.Forms自定义ViewCell/ImageCell

Nik*_*Nik 1 customization listview xamarin xamarin.forms

我已将我的ImageCell更改为自定义ViewCell,其中包含am图像和三个标签.

ImageCell正在为细胞加载图像,就在它们出现在屏幕上时.我的自定义单元格在初始加载期间加载所有ViewCell的所有图像.

我该如何解决这个问题,或者如何增强自定义ViewCell以实现相同的行为?

谢谢,尼古拉

Mat*_*att 5

在您的CustomViewCell中,您只需要覆盖OnAppearingOnDisappearing.

滚动时会调用这两个事件

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()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)