简体   繁体   English

Xamarin.Forms自定义ViewCell / ImageCell

[英]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中,您只需要重写OnAppearingOnDisappearing

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.

相关问题 相对于Xamarin.Forms中的ViewCell更新视图 - Updating View with respect to ViewCell in Xamarin.Forms Xamarin.Forms-将FFImageLoading与ListView.ImageCell一起使用 - Xamarin.Forms - Using FFImageLoading with ListView.ImageCell 如何在自定义 Xamarin.Forms ViewCell 上的行之间添加分隔符空间? - How to add a separator space between rows on custom Xamarin.Forms ViewCell? ListView中的可折叠自定义viewcell-Xamarin Forms - Collapsable custom viewcell in ListView - Xamarin Forms Xamarin.Forms在ViewView的ViewCell中将ViewModel作为BindingContext获取 - Xamarin.Forms get ViewModel as BindingContext in ViewCell of ListView Xamarin.Forms - 更新ItemSource时,ViewCell内的图像闪烁 - Xamarin.Forms - Image inside ViewCell flashes when updating the ItemSource Xamarin.Forms MVVM TapGestureRecognizer 到 ListView 的 ViewCell 中的标签(在部分文件中) - Xamarin.Forms MVVM TapGestureRecognizer to a Label in a ViewCell of ListView (in partial files) 如何在Xamarin.Forms中点击以切换ListView ViewCell属性的可见性 - How to toggle visibility of ListView ViewCell attribute on tap in Xamarin.Forms 如何从 Xamarin.Forms 删除 ViewCell 中的边框? - How to delete border in ViewCell From Xamarin.Forms? 如何从 Xamarin Forms 中的自定义 ViewCell 获取 ListView 项目索引? - How to get ListView item index from custom ViewCell in Xamarin Forms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM