如何使用Mvvmcross将图像src绑定到资源可绘制图像? [英] how to bind an image src to resource drawable image with Mvvmcross?

查看:66
本文介绍了如何使用Mvvmcross将图像src绑定到资源可绘制图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绑定图像的src.

I'm trying to bind an image's src.

我已经尝试过使用MvxHttpImageView

I have tried using MvxHttpImageView like this

<Mvx.MvxHttpImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/iconeView"
                local:MvxBind="{'ImageUrl':{'Path':'ImgSrc'}}" />

public string ImgSrc
{
    get {return "@res/drawable/icon.png"; }
}

我尝试了其他几个ImgSrc,但仍然没有任何结果.

I have tried several other ImgSrc and still don't have any result.

icon.png在我的Resources/Drawable目录中,并且是AndroidResource

icon.png is in my Resources/Drawable directory and is an AndroidResource

任何帮助都会很棒! 谢谢

any help will be great ! Thanks

推荐答案

mvxhttpimageview知道如何从http和磁盘"中加载图像

The mvxhttpimageview knows how to load images from http and from 'disk'

可悲的是,它不知道如何从资源中加载

Sadly, it doesn't know how to load from resources

但是,有一些方法可以使图像加载静态内容.

However, there are ways to get an image to load static content.

  1. 您可以编写自己的自定义绑定
  2. 您可以使用标准的imageview,存储在android资源中的图像以及mvx中内置的"AssetImagePath"绑定.

要尝试第一个,请看一下会议示例-最喜欢的按钮背景如何绑定到IsFavorite

To try the first, take a look at the conference sample - at how the favorite button background is bound to IsFavorite

第二步:

  • 在资产文件夹中添加图标-例如/assets/icon1.png
  • 确保将构建操作设置为AndroidAsset
  • 在XML中使用标准的ImageView和绑定文本,例如{'AssetImagePath':{'Path':'WhichAsset'}}

在实际使用中,我通常还会使用一个转换器-可以将viewmodel属性(例如State)映射为State,其值为LoadingState.Loading到资产图像路径(例如'/loadingimages/loading.png'

In real use, I generally also use a converter - something that maps a viewmodel property like State with a value of LoadingState.Loading to an asset image path like '/loadingimages/loading.png'

您可以在 https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross.Binding/Android/Target/MvxImageViewDrawableTargetBinding.cs

对不起,答案没有包含更多代码-在移动设备上回答

Sorry answer doesn't include more code - answering on mobile

这篇关于如何使用Mvvmcross将图像src绑定到资源可绘制图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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