I'm using MvvmCross 3.0.14 with Xamarin.Android.
I have an MvxImageView that I can get to display a particular local graphics resource if I specify the image directly (without binding) using android:src:
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
android:src="@drawable/Card_kh"/>
But I can't get the same image to show up using local:MvxBind:
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl 'res:Card_kh'"/>
This does not work. MvxAndroidLocalFileImageLoader.LoadResourceBitmap logs a trace message indicating that 'Card_kh' was not a known drawable name. It's encouraging that it got that far -- at least I know that the intended consumer of this information did get it. But apparently I have not provided that information in the correct format.
Taking it one step further, my actual goal is to have my ViewModel determine what resource should be used, e.g.
class MyViewModel : MvxViewModel
{
public string SomeImagePath { get { return "res:Card_kh"; } }
}
and
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl SomeImagePath"/>
What do I need to do to have an MvxImageView bind to a view-model determined local resource image?
The problem was only capitalization in the resource name. Although the image filename starts with a capital C, and the android:src attribute works with a capital C, the MvxBind of ImageUrl requires a lowercase c:
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl 'res:card_kh'"/>
This also solves the problem when the source of the ImageUrl value is a viewmodel property:
class MyViewModel : MvxViewModel
{
public string SomeImagePath { get { return "res:card_kh"; } }
}
and
<Mvx.MvxImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImageUrl SomeImagePath"/>
The previous answer is not working anymore since MVVMCross v6.0.0.
As described here https://www.mvvmcross.com/documentation/upgrading/upgrade-to-mvvmcross-60 MvxImageView has been removed from the API.
The newest alternative is now https://github.com/luberda-molinet/FFImageLoading/wiki/MvvmCross.
This nuget package "Xamarin.FFImageLoading" must be added in order to make the code below work.
<ffimageloading.cross.MvxCachedImageView
android:layout_width="100dp"
android:layout_height="75dip"
android:layout_weight="1"
local:MvxBind="ImagePath SomeImagePath"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With