android mvvm 找不到属性绑定,MVVMCross将ImageView交叉绑定到android资源ID而不是资产路径...

I have a layout with an ImageView in it. I want to show a different image, depending on logic in my core project. Adding the images to the assets folder and binding it up with a converter works. For my ValueConverter:

public class MyImageValueConverter : MvxValueConverter

{

protected override string Convert(MyMap value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

return GetResourcePath(value);

}

private string GetResourcePath(MyMap map)

{

string path = "";

switch (map)

{

case MyMap.Map1:

path = "map1.png";

break;

case MyMap.Map2:

path = "map2.png";

break;

default:

throw new Exception("no image for map: " + map.ToString());

}

return path;

}

}

In my view, i bind it up like this:

...

var map = FindViewById(Resource.Id.my_imageview);

set.Bind(map).For("AssetImagePath").To(vm => vm.CurrentMap).WithConversion("MyImage");

...

Now to my question. I would very much prefer to set the image from a resource drawable instead, but i have not found a way to do this. I feel like i should just be able to return a resource ID from my converter, and bind it to some property (which?).

Alternatively i could just create a new class that inherits from MvxImageView and add a property that i could do a one-way binding to, that calls SetImageResource(). Or even go the full custom binding way. None of these seem very nice.

Solutions1

Bind to MvxImageView's DrawableId

Look to MvxAndroidBindingBuilder, it has some hidden gems:

Talk1:

Thank you! The BindingBuilder is an excellent resource to discover these otherwise somewhat "hidden" binding properties

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值