Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ListView中的ImageView在启用了RecycleElement的情况下简要显示上一个滚动图像_Ios_Xamarin_Xamarin.forms - Fatal编程技术网

Ios ListView中的ImageView在启用了RecycleElement的情况下简要显示上一个滚动图像

Ios ListView中的ImageView在启用了RecycleElement的情况下简要显示上一个滚动图像,ios,xamarin,xamarin.forms,Ios,Xamarin,Xamarin.forms,我有以下班级的名单: public class Set { public string IconUrl { get; set; } } 此列表已绑定到ListView: <ListView ItemsSource="{Binding Sets}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Vie

我有以下班级的名单:

public class Set {
   public string IconUrl { get; set; }
}
此列表已绑定到ListView:

<ListView ItemsSource="{Binding Sets}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <Image Source="{Binding IconUrl}" />
                </ViewCell.View>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

当视图加载且用户开始滚动时,单元格将被重新使用,并且在下载和渲染新图像之前,图像将短暂显示以前的图像


有没有一种方法可以在不禁用RecycleElement的情况下防止这种行为?

我没有尝试过这种方法,但是在
ViewCell
上,您可以连接到
消失和
出现的事件


您可能希望在
消失事件处理程序上释放图像源,但有时这种情况可能会在稍后发生,我回想起来,因此,您可能还想尝试在出现的
事件处理程序上释放图像,希望在屏幕显示之前执行该处理程序。

我们已通过手动将图像源设置为null来解决此问题,以强制渲染新图像。我们通过使用ListView的OnBindingContextChanged事件来实现这一点。希望这有帮助

已编辑(在下面添加代码):

我们有这样的东西:

public class PeopleCell : ViewCell
{...

Image profileImage;

public PeopleCell()
{
    profileImage = new Image
    {
        VerticalOptions = LayoutOptions.CenterAndExpand,
        HorizontalOptions = LayoutOptions.CenterAndExpand,
        BackgroundColor = Color.FromHex("f5f5f5"),
        Source = ImageSource.FromFile("profile_blankimage"),
    };...

protected override void OnBindingContextChanged()
{
    base.OnBindingContextChanged();
    people = BindingContext as CustomerViewModel;


    if(people.Customer.Avatar != null)
       profileImage.Source = ImageSource.FromUri(new Uri(people.Customer.Avatar.Url));

如何引用OnBindingContextChanged事件中的图像?你能添加一些代码吗?我已经添加了一些我们使用过的示例代码,我希望这会有所帮助。啊,自定义ViewCell,这意味着你没有使用XAML,对吗?不,没有XAML,很抱歉我错过了。你能包括你在哪里将图像源设置为null吗?我假设OnBindingContextChanged中有,但只是想确定一下。我已经尝试了消失事件,不幸的是,它没有在我需要的时候持续触发。我会尝试参加这次活动,但我猜会更糟;)你能不能制作一个小的演示,我会仔细看看你有什么?如果是的话,我的详细信息在我的个人资料中。