Struggling to bind local images in an MvxImageView with MvvmCross

前端 未结 3 539
终归单人心
终归单人心 2021-01-19 13:46

I can\'t seem to get images to bind properly in an MvxListView

Here is the template:




        
相关标签:
3条回答
  • 2021-01-19 14:17

    Thanks ,it's working.Tried with MVXImageview

     public class PercentToImageConverter : MvxValueConverter<int, int>   
      {         
       protected override int Convert(int value, Type targetType, object parameter, CultureInfo culture)
    
        {    
                switch (value)
                {
                    case 10:
                        return Resource.Drawable.Percent10;
                    case 40:
                        return Resource.Drawable.Percent40;
                    case 60:
                        return Resource.Drawable.Percent60;
                    case 80:
                        return Resource.Drawable.Percent80;
                    case 100:
                        return Resource.Drawable.Percent100;
                    default:
                        return Resource.Drawable.Percent0;    
                 }
    
        }
    
    }
    

    Android Layout

    <Mvx.MvxImageView
       android:layout_width="25dp"
       android:layout_gravity="center"
       android:layout_height="25dp"
      local:MvxBind="DrawableId PercentToImage(Percent)" />
    
    0 讨论(0)
  • 2021-01-19 14:21

    In xml use: local:MvxBind="ImageUrl IconName" In ViewModel: IconName="res:image_name"

    eg.In drawable resource image name like "image_name.png"

    0 讨论(0)
  • 2021-01-19 14:22

    I have used this to make it work for me:

    public class StringToIntValueConverter : MvxValueConverter<string, int>
                {
                    protected override int Convert(string value, Type targetType, object parameter, CultureInfo culture)
                    {
                        int image = 0;
                        if(value == "song")
                            image = Resource.Drawable.icon_category_song;
    
                        return image;
                    }
                }
    

    To use this in the Android layout:

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            local:MvxBind="DrawableId StringToInt(Type)" />
    

    In this example "Type" is a string containing the word "song".

    0 讨论(0)
提交回复
热议问题