【问题标题】:Xamarin forms: Different item is invoking instead of selected item in flowlistview?Xamarin 表单:不同的项目正在调用而不是 flowlistview 中的选定项目?
【发布时间】:2020-04-04 15:41:59
【问题描述】:

最近我发了一个与flowlistview项目可见性相关的question,这个问题也与此有关。

我在列表中有 8 张图片,最初显示的是问号图片。当点击问号图像时,真实图像将在问号图像下方可见。使用最近的线程实现了此功能。

这是一款儿童游戏。 游戏规则:玩家首先点击一个图像,然后玩家可以看到真实的图像。然后玩家点击另一个图像,然后玩家现在也可以看到该真实图像。如果图像匹配,玩家将获得积分,并且两个选定的项目都将从 UI 中删除。如果不匹配再次隐藏带有问号图像的真实图像。

上面的事情我都做了,但是问题是有时候图片的选择是错误的。如果我选择第四张图像,则第二张或第六张下的图像将显示在 UI 中。不知道这背后的原因是什么。我已经上传了一个示例项目here

【问题讨论】:

  • FlowListView 可能有问题你试过用 XF CollectionView 代替吗?

标签: listview xamarin.forms visibility


【解决方案1】:

原因:您通过确定图片的 imageUrl 是否相等来匹配图片。 但是 imageUrl 在 List 中并不是唯一的。

解决方案:您可以在模型中添加一个属性Id

public int Id { get; set; }

并通过确定项目的 Id 是否相等来处理逻辑。

ImageItems.Add(new NameMatchList() { Id = 1,imageUrl = "/cbrain-app/files/doc-lib/2018/02/22/11/46/06/971/head/Comfort the Sorrowing.png" });
ImageItems.Add(new NameMatchList() { Id = 2, imageUrl = "/cbrain-app/files/doc-lib/2018/02/22/11/46/23/784/head/Giving Food To The Hungry.png" });
//...
if (items.Id == selecteditem.Id)
{
   if (!firstImageFlipped)
   {
     items.ImageVisibility = true;
     items.TopImageVisibility = false;
     firstImageFlipped = true;
     Application.Current.Properties["FirstImageUrl"] = selecteditem.imageUrl;
     Application.Current.Properties["FirstImageItem"] = selecteditem;
   }
}

【讨论】:

猜你喜欢
  • 2019-06-05
  • 2020-04-04
  • 2021-06-11
  • 2019-06-12
  • 1970-01-01
  • 2020-03-26
  • 1970-01-01
  • 2018-11-30
  • 2020-02-22
相关资源
最近更新 更多