本地源映像绑定到MvxImageView

时间:2015-08-11 11:56:55

标签: android xamarin imageview mvvmcross

 public class DrawerView
{
    public string ListItem{get;set;}
    public string icon{ get; set;}
    public DrawerView (string Litems,string ic)
    {
        this.ListItem = Litems;
        this.icon = ic;
    }
}

 public class MainViewModel:MvxViewModel
{
    public List<DrawerView> drawerlist{ get; set;}
    public MainViewModel ()
    {
        drawerlist = new List<DrawerView> ();
        drawerlist.Add (new DrawerView ("Home","@drawable/Home"));
        drawerlist.Add (new DrawerView ("My Addresses","@drawable/Home"));
        drawerlist.Add (new DrawerView ("My Cart","/@drawable/Home"));
        drawerlist.Add (new DrawerView ("My Orders","@drawable/Home"));
        drawerlist.Add (new DrawerView ("Notification","@drawable/Home"));
    }
}


 <Mvx.MvxImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:padding="10dp"
    local:MvxBind="ImageUrl 'res:icon'"
    />

当我使用图片网址点击本地@ drawable / Home图像时,我无法在View中获取图像。 如何在MvxImageView中绑定本地源图像?上面的代码图标是我的字符串属性,需要@ drawable / images。

1 个答案:

答案 0 :(得分:0)

这是我使用转换器的方式:

<Mvx.MvxImageView
    android:id="@+id/team_trend"
    android:layout_width="24dp"
    android:layout_height="8dp"
    android:gravity="center_vertical"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    local:MvxBind="ImageUrl RowItem.TeamTrendEnum, Converter=TeamTrendImage" />

我的转换器返回图像:

public class TeamTrendImageValueConverter : MvxValueConverter
{
    public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {            
        var teamTrend = TeamTrendEnumeration.None;

        if (value != null)
            teamTrend = (TeamTrendEnumeration)value;

        switch (teamTrend)
        {
            case TeamTrendEnumeration.High: 
                return "res:th";

            ...                                           
        }

        return "res:none";                  
    }
}

您是否尝试删除引号?