how to bind an image src to resource drawable image with Mvvmcross?

后端 未结 4 1187
走了就别回头了
走了就别回头了 2020-12-20 12:38

I\'m trying to bind an image\'s src.

I have tried using MvxHttpImageView like this



        
4条回答
  •  北海茫月
    2020-12-20 13:30

    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.

    1. You can write you own custom binding
    2. You can use the standard imageview, images stored in android assets and the 'AssetImagePath' binding built into mvx.

    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:

    • include the icons in the asset folder - e.g. /assets/icon1.png
    • make sure the build action is set to AndroidAsset
    • in the XML use a standard ImageView and binding text like {'AssetImagePath':{'Path':'WhichAsset'}}

    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

提交回复
热议问题