I'm trying to bind an image's src.
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'}}" />
with
public string ImgSrc
{
get {return "@res/drawable/icon.png"; }
}
I have tried several other ImgSrc and still don't have any result.
icon.png is in my Resources/Drawable directory and is an AndroidResource
any help will be great ! Thanks
Newer versions of MvvmCross support binding to a drawable resources. Using the DrawableName binding you can bind an ImageView to a property on your viewmodel that contains a drawable name.
And in your layout
Alternatively, you could use the Drawable binding if your VM property is an
int
I built a converter, which converts a drawable name to a Bitmap and bound the Bitmap to the ImageView.
The converter:
The XML view:
The
Icon
property I'm binding is a string like: "icon_name" where I put the imageicon_name.png
in the Android project'sResources/drawable
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.
To try the first, take a look at the conference sample - at how the favorite button background is bound to IsFavorite
To do the second:
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'
You can see the code for the asset binding in 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
For latest MvvmCross next solution is actual:
In markup:
In converter:
All sense is that you just must give out a drawable resource id.