如何动态多次绑定到ImageView

时间:2015-08-21 09:18:05

标签: xamarin.android mvvmcross

我想将mvvmcross绑定到ImageView属性:

1)点击
2)ImageUrl - 更改图像
3)启用

in Layout file:

<ImageView

    android:id="@+id/imgTest"

    android:src="@drawable/Img_Test"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"    
    android:maxHeight="80dp"
    android:maxWidth="80dp"   
    android:layout_margin="20dp"   
    android:scaleType="fitCenter"

    local:MvxBind ="      " /
资源中的

我在资源文件夹中有两个图像

1)ImgTest_Normal.png
2)ImgTest_Grey.png

in ivalue Converter :


public class MyTargetImageValueConverter : MvxValueConverter<bool, string>
{
    protected override string Convert(bool value, Type targetType, object parameter, CultureInfo culture)
    {
        if(value)
        {
            return "res:ImgTest_Normal";
        }
        else
        {
            return "res:ImgTest_Grey";
        }
    }
}
绑定中的

local:MvxBind =&#34;点击命令[DisplayCase];已启用AuthCommand(&#39; View_user&#39;); ImageUrl MyTargetImage(false)&#34;

为什么这不起作用?任何想法?

1 个答案:

答案 0 :(得分:1)

您需要使用MvxImageView才能绑定到ImageUrl

所以将AXML布局更改为:

<Mvx.MvxImageView
    android:id="@+id/imgTest"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"    
    android:maxHeight="80dp"
    android:maxWidth="80dp"   
    android:layout_margin="20dp"   
    android:scaleType="fitCenter"
    local:MvxBind="Click Commands[DisplayCase]; Enabled AuthCommand('View_user'); ImageUrl MyTargetImage(false)" />

我不知道您要绑定到Enabled属性的是什么,但它看起来并不正确。