挣扎在MvvmCross的MvxImageView结合本地图片 [英] Struggling to bind local images in an MvxImageView with MvvmCross
本文介绍了挣扎在MvvmCross的MvxImageView结合本地图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法让图像在MvxListView正确绑定
I can't seem to get images to bind properly in an MvxListView
下面是模板:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
local:MvxBind="ImageUrl IconName, Converter=IconSource" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
local:MvxBind="Text Name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
local:MvxBind="Text Description" />
</LinearLayout>
</LinearLayout>
下面是转换器:
public class IconSourceValueConverter : MvxValueConverter<string, string>
{
protected override string Convert(string value, Type targetType, object parameter, CultureInfo culture)
{
//string retval = string.Format("res:{0}", value.ToLower());
string retval = string.Format("@drawable/{0}", value.ToLower());
return retval;
}
}
所有的图像都present在绘制对象文件夹。
All the images are present in the Drawable folder.
我都尝试绘制和资源,并没有工作。
I tried both drawable and res and neither work.
我更换了MvxImageView用含有硬codeD Android的一个普通的ImageView:src和它工作得很好
I replaced the MvxImageView with a plain ImageView containing a hard coded android:src and it worked fine.
任何想法?
推荐答案
我已经使用这个,使其为我工作:
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;
}
}
要在Android布局中使用这样的:
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".
这篇关于挣扎在MvvmCross的MvxImageView结合本地图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文