MvxImageView,无法将ImageUrl绑定到本地资源 [英] MvxImageView, can't bind ImageUrl to local resource

查看:58
本文介绍了MvxImageView,无法将ImageUrl绑定到本地资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xamarin.Android上使用MvvmCross 3.0.14.

I'm using MvvmCross 3.0.14 with Xamarin.Android.

我有一个MvxImageView,如果我直接使用android:src指定图像(无绑定),就可以显示特定的本地图形资源.

I have an MvxImageView that I can get to display a particular local graphics resource if I specify the image directly (without binding) using android:src:

<Mvx.MvxImageView
  android:layout_width="100dp"
  android:layout_height="75dip"
  android:layout_weight="1"
  android:src="@drawable/Card_kh"/>

但是我无法使用local:MvxBind来显示同一张图片:

But I can't get the same image to show up using local:MvxBind:

<Mvx.MvxImageView
  android:layout_width="100dp"
  android:layout_height="75dip"
  android:layout_weight="1"
  local:MvxBind="ImageUrl 'res:Card_kh'"/>

这不起作用. MvxAndroidLocalFileImageLoader.LoadResourceBitmap记录一条跟踪消息,指示"Card_kh"不是已知的可绘制名称.令人鼓舞的是,它达到了如此之遥-至少我知道此信息的目标用户确实能够获得它.但是显然我没有以正确的格式提供该信息.

This does not work. MvxAndroidLocalFileImageLoader.LoadResourceBitmap logs a trace message indicating that 'Card_kh' was not a known drawable name. It's encouraging that it got that far -- at least I know that the intended consumer of this information did get it. But apparently I have not provided that information in the correct format.

再进一步,我的实际目标是让ViewModel确定应使用哪种资源,例如

Taking it one step further, my actual goal is to have my ViewModel determine what resource should be used, e.g.

class MyViewModel : MvxViewModel
{
  public string SomeImagePath { get { return "res:Card_kh"; } }
}

<Mvx.MvxImageView
  android:layout_width="100dp"
  android:layout_height="75dip"
  android:layout_weight="1"
  local:MvxBind="ImageUrl SomeImagePath"/>

我需要怎么做才能将MvxImageView绑定到视图模型确定的本地资源图像?

What do I need to do to have an MvxImageView bind to a view-model determined local resource image?

推荐答案

问题仅在于资源名称中的大写字母.尽管图片文件名以大写字母C开头,而android:src属性以大写字母C开头,但是ImageUrl的MvxBind需要小写的c:

The problem was only capitalization in the resource name. Although the image filename starts with a capital C, and the android:src attribute works with a capital C, the MvxBind of ImageUrl requires a lowercase c:

<Mvx.MvxImageView
  android:layout_width="100dp"
  android:layout_height="75dip"
  android:layout_weight="1"
  local:MvxBind="ImageUrl 'res:card_kh'"/>

当ImageUrl值的源是viewmodel属性时,这也解决了问题:

This also solves the problem when the source of the ImageUrl value is a viewmodel property:

class MyViewModel : MvxViewModel
{
  public string SomeImagePath { get { return "res:card_kh"; } }
}

<Mvx.MvxImageView
  android:layout_width="100dp"
  android:layout_height="75dip"
  android:layout_weight="1"
  local:MvxBind="ImageUrl SomeImagePath"/>

这篇关于MvxImageView,无法将ImageUrl绑定到本地资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆