Xamarin形式:正在调用不同的项目而不是flowlistview中的选定项目? [英] Xamarin forms: Different item is invoking instead of selected item in flowlistview?

查看:87
本文介绍了Xamarin形式:正在调用不同的项目而不是flowlistview中的选定项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我发布了一个问题flowlistview项目可见性有关,这个问题也与此有关.

Recently I have posted a question related to flowlistview item visibility, this question is also related to that.

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

I have 8 images in a list, initially show a question mark image. When tap on the question mark image, the real image will visible under the question mark image. Implemented this feature using the recent thread.

这是为孩子们设计的游戏. 游戏规则:玩家首先点按一张图片,然后即可看到真实的图片.然后,播放器轻拍另一张图像,然后该真实图像现在也对播放器可见.如果图像匹配,则玩家将获得积分,并且两个选定的项目都将从用户界面中删除.如果不匹配,请再次隐藏带有问号图像的真实图像.

This is a game for kids. Game rule: The player first taps one image, then the real image is visible to the player. Then the player taps another image, then that real image also visible to the player now. If the images match the player gets points and both selected items will be removed from the UI. If not match again hide the real image with question mark image.

我已经完成了上述操作,但是问题有时是图像选择错误.如果选择第四张图像,则第二张或第六张下面的图像将显示在UI中.不知道这背后的原因是什么.我已经在此处上传了示例项目.

I have done the above things, but the problem is sometimes the selection of images is wrong. If I select the fourth image, the image under the second or sixth is showing in UI. Don't know what is the reason behind this. I have uploaded a sample project here.

推荐答案

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

Cause: You matched the pictures by determining whether their imageUrl are equal . But the imageUrl is not unique in the List .

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

Solution: You could add a property Id in the model .

public int Id { get; set; }

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

And handle the logic by determining if item's Id are equal .

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;
   }
}

这篇关于Xamarin形式:正在调用不同的项目而不是flowlistview中的选定项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆