简体   繁体   中英

Xamarin.Forms Custom ViewCell / ImageCell

I have changed my ImageCell to a custom ViewCell holding am image and three labels.

The ImageCell was loading images for cells just when they appear on the screen. My custom cell loads all images of all ViewCells during the initial load.

How can I fix this, or how can I enhance my custom ViewCell to implement the same behaviour?

Thanks, Nikolai

In your CustomViewCell you just need to override OnAppearing and 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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM