Forum Xamarin.iOS

UIImageView binding MvvmCross

Zebiphire67Zebiphire67 Member ✭✭
edited July 2019 in Xamarin.iOS

Hello,

I have a question. I was wondering how to bind a UIImageView element declared in an XIB file?
I'm trying to use > public virtual UIImage Image { get; set; }.

I have something like:

 private MvxFluentBindingDescriptionSet<ViewController, ViewModel> _setBinding;
_setBinding = this.CreateBindingSet<ViewController, ViewModel>();

This doesn't work:

_setBinding.Bind(_imageDescription.Image).To(vm => vm.ImageName);

_imageDescription:

 [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        UIKit.UIImageView _imageDescription { get; set; }

ImageName:

   public string ImageName
        {
            get
            {
                if (_productItemViewModel.ProductNumber % 2 == 0)
                {
                    return _imageNameEven;
                }
                else
                {
                    return _imageNameOdd;
                }
            }
        }

The binding work with Xamarin.Forms.Android/iOS and Xamarin.Android.
I don't know how can I bind the name of the image for Xamarin.iOS.

Thank for the help.
Zebiphire

Posts

  • Zebiphire67Zebiphire67 Member ✭✭

    Hello again.

    A possible solution to the problem.

    Replace:

    _setBinding.Bind(_imageDescription.Image).To(vm => vm.ImageName);
    by
    _setBinding.Bind(this).For(v => v.ImageFilePath).To(vm => vm.ImageName);

    where:

                public string ImageFilePath
                {
                    get
                    {
                        return _imageFilePath;
                    }
                    set
                    {
                        _imageFilePath = value;
                        _imageDescription.Image = new UIImage(_imageFilePath);
                    }
                }
    

    :-)

Sign In or Register to comment.