我有一个xamarin形式的相对简单的应用程序,它具有带有自定义单元格的ListView。在这些单元格中,有一个图像。我遇到的问题是这个。当我滚动ListView时,可以在加载新图像之前先查看一下先前单元格中的图像。
我尝试将ListView设置ListViewCachingStrategy
为所有可能的值,但问题仍然存在。
有没有办法停止回收?我知道这对性能有很大影响,但是列表并不那么大。当然,除非有更好的方法来解决此图像问题
您可以替代OnBindingContextChanged
使用绑定重写ViewCell的方法。像这样:
protected override void OnBindingContextChanged()
{
image.Source = null;
base.OnBindingContextChanged();
var item = BindingContext as YourItemType;
if (item == null)
return;
image.Source = item.YourImageSource;
}
在此处阅读更多信息:https : //developer.xamarin.com/guides/xamarin-forms/user-interface/listview/performance/#RecycleElement
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句