有谁知道如何一个byte [](图片)绑定到一个AXML视图中的图像控制。 我的视图模型继承MvxViewModel。 我所有的其他绑定的伟大工程,但我不能找到一种方法来绑定的形象。
Does anyone know how to bind a byte[] (image) to a Image control in a axml view. My ViewModel inherit from MvxViewModel. All my other bindings works great but I cannot find a way to bind that image.
我想你可以使用一个自定义的UI控件绑定这一点。
I think you could bind this using a custom UI control.
要做到这一点,你需要做的是这样的:
To do this, you'll need to do something like:
在继承一个新的 MyImageView
从的ImageView
添加默认的构造方法(通过上下文和属性到基构造)
新 RawImage
属性添加到 MyImageView
,其实现为:
inherit a new MyImageView
from ImageView
add the default constructor (which passes the context and attributes down to the base constructor)
add a new RawImage
property to MyImageView
, implementing it as:
private byte[] _rawImage;
public byte[] RawImage
{
get { return _rawImage; }
set
{
_rawImage = value;
if (_rawImage == null)
return;
var bitmap = BitmapFactory.DecodeByteArray(_rawImage, 0,_rawImage.Length);
SetImageBitmap(bitmap);
}
}
然后,您可以使用 MyImageView
在AXML而不是正常的 ImageView的控制
。
You can then use that MyImageView
control in your axml instead of the normal ImageView
.
请注意 - 这code以上没有测试 - 但一旦你得到的byte []中查看我敢肯定,你会工作了使用什么样的Droid的code
Note - this code above not tested - but once you get the byte[] in the View I'm sure you'll work out what Droid code to use.
作为一种替代方法,您也可以使用自定义绑定绑定字节[]
来正常的ImageView
- 见In MvvmCross我该怎么做自定义的绑定属性
As an alternative approach to this, you could also use a custom binding to bind a byte[]
to a normal ImageView
- see an example of custom binding in In MvvmCross how do I do custom bind properties