如何动态多重绑定到 ImageView
How to dynamically multiple binding to an ImageView
我想执行 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";
}
}
}
在绑定中:
本地:MvxBind ="Click Commands[DisplayCase]; Enabled AuthCommand('View_user'); ImageUrl MyTargetImage(false)"
为什么这不起作用?有什么想法吗?
您需要使用 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
属性 上的是什么,但它看起来不对。
我想执行 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";
}
}
}
在绑定中:
本地:MvxBind ="Click Commands[DisplayCase]; Enabled AuthCommand('View_user'); ImageUrl MyTargetImage(false)"
为什么这不起作用?有什么想法吗?
您需要使用 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
属性 上的是什么,但它看起来不对。