Forum Xamarin Cross Platform with Xamarin

MVVMCross MvxTouchLocalFileImageLoader


I'm using MVVMCross MvxTouchLocalFileImageLoader to load a local image in to a UIImageView.

Does anyone know of a way to bind a property to the MvxTouchLocalFileImageLoader and return the image?

Similar to how you would do with MvxImageViewLoader:

var imageLoader = new MvxImageViewLoader(() => ImageView);
set.Bind(imageLoader).To(x => x.ImagePath);

Any pointers appreciated.



  • khoanguyenvankhoanguyenvan USMember ✭✭


    You can do like that:
    Build converters:

    public class IconPathToImageConverter : MvxValueConverter<string, UIImage>
    protected override UIImage Convert (string value, Type targetType, object parameter, CultureInfo culture)
    var loader = parameter as MvxTouchLocalFileImageLoader;
    var mvxImage = loader.Load ((string)value, true);
    return mvxImage.RawImage;

    At YourViewModel.cs:

    public YourViewModel
    public YourImagePath{get;set;} // must return full path like: /Images/yourpicture.png

    At YourView.cs:

    var youImageView = new MvxImaheView();
    var imageLoader = new MvxTouchLocalFileImageLoader( );

    And Bidding:

    var set = this.CreateBindingSet<YouView, YourViewModel> ();
    set.Bind (roomIcon).For(x=>x.Image).To (vm => vm.YourImagePath).WithConversion("IconPathToImage", imageLoader );

    If you don't understand, you can contact me at skype: khoanguyenvan

Sign In or Register to comment.