使用MvxImageViewLoader加载资源图像,可以吗? [英] Using MvxImageViewLoader to load a resource image, is it possible?

查看:62
本文介绍了使用MvxImageViewLoader加载资源图像,可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MvxTableViewCell中使用mvvmcross绑定,单元格元素是一个UIImageView和2个标签.

I'm using mvvmcross binding in a MvxTableViewCell, the cell elements are an UIImageView and 2 labels.

这些行"/单元格将列出一组预定义的元素,这些元素的图像是png文件,这些文件存在于Resources目录(捆绑资源)或互联网上的任何位置.

These "rows"/cells will list a set of predefined elements, the image of these elements are png files that exist inside the Resources directory (bundle resource) or at any place on the internet.

由于我可能会把捆绑包和互联网上存在的图像混合在一起,所以我想使用MvxImageViewLoader.

Since I might have this mix of images that exist in the bundle and on the internet I would like to use MvxImageViewLoader.

视图模型有一个对象列表,这些对象包含一个属性,即图像uri,对于资源图像,我尝试了几种解决方案: -NSBundle.MainBundle.ResourcePath +"/xpto.png" -"file://" + NSBundle.MainBundle.ResourcePath +"/xpto.png"

The view model has a list of objects that contain a property that is the image uri, for the resource images I tried several solutions: - NSBundle.MainBundle.ResourcePath+"/xpto.png" - "file://" + NSBundle.MainBundle.ResourcePath+"/xpto.png"

位于互联网上的所有图像都可以正常工作.

All the images that are located in the internet work without any problem.

是否可以使用MvxImageViewLoader加载资源文件夹中存在的图像?我应该使用转换器吗?

Is it possible to use MvxImageViewLoader to load images that exist in the resource folder? Should I use a converter?

感谢您的帮助,

路易斯·皮尼奥(Luis Pinho)

Luis Pinho

推荐答案

Touch上的MvvmCross DownloadCache插件可将图像加载解析为:MvxTouchLocalFileImageLoader-请参见

The MvvmCross DownloadCache plugin on Touch resolves image loading to: MvxTouchLocalFileImageLoader - see https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/DownloadCache/Cirrious.MvvmCross.Plugins.DownloadCache.Touch/MvxTouchLocalFileImageLoader.cs

这使用res:作为方案/前缀来检测是否已请求资源文件,然后使用UIImage.FromFile加载它们.

This uses res: as the scheme/prefix to detect whether a resource file has been requestd and then uses UIImage.FromFile to load them.

由于其他平台不支持使用相同前缀的资源文件,因此您可能会发现在移至多个平台时需要为此使用值转换器.

Since other platforms do not support resource files using the same prefix, you may find you need to use a value converter for this when moving to multiple platforms.

或者,您可以轻松实现从MvxImageView继承的自己的MyImageView控件,该控件将拦截绑定的属性并决定是下载还是从资源中显示它.

Alternatively, you could easily implement your own MyImageView control inheriting from MvxImageView which would intercept the bound property and decide whether to download it or to display it from resources.

这篇关于使用MvxImageViewLoader加载资源图像,可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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