Xamarin.android 在MvxImageView控件中设置占位符图像

Xamarin.android 在MvxImageView控件中设置占位符图像,xamarin.android,mvvmcross,Xamarin.android,Mvvmcross,我使用MvxImageView控件绑定了大量搜索结果。当应用程序下载每个图像时,图像渲染时有时会有一个小的等待。目前这意味着搜索结果在呈现之前是白色的 我希望在MvxImageView中有一个占位符图像,其方式与在标准ImageView控件中放置占位符图像的方式相同 这是代码 <Mvx.MvxImageView android:id="@+id/item_searchresult_imageView" android:src="@drawable/product_placehold

我使用MvxImageView控件绑定了大量搜索结果。当应用程序下载每个图像时,图像渲染时有时会有一个小的等待。目前这意味着搜索结果在呈现之前是白色的

我希望在MvxImageView中有一个占位符图像,其方式与在标准ImageView控件中放置占位符图像的方式相同

这是代码

<Mvx.MvxImageView
  android:id="@+id/item_searchresult_imageView"
  android:src="@drawable/product_placeholder"
  android:layout_gravity="center|top"
  android:layout_width="170dp"
  android:layout_height="128dp"
  android:layout_marginTop="10dp"
  android:layout_marginRight="10dp"
  android:layout_marginLeft="10dp"
  local:MvxBind="ImageUrl SearchResult.ProductImageId, Converter=PowerStorageImage" />
在加载主图像之前似乎没有正确设置,并且在加载之前搜索结果仍然是黑白的

谢谢

编辑


我还应该指出,在某些情况下,结果实际上没有图像,在这种情况下,我希望保留占位符图像。

您的建议与BookSellers示例中使用的占位符模式相同:

<Mvx.MvxImageView
  android:id="@+id/BookImageView"
  android:layout_width="80dp"
  android:layout_height="80dp"
  android:padding="8dp"
  android:src="@drawable/icon"
  local:MvxBind="ImageUrl AmazonImageUrl"
  />

在下载
ImageUrl
需要几秒钟的情况下,它似乎可以正常工作

如果您有一些客户用例,其中有时有图像,有时是现在,那么您可以尝试为您的特定用例编写一些代码,例如:

  • 使用valueconverter检测ImageUrl何时无效,并将其替换为某个自定义url(可能是本地文件)
  • 使用自定义控件而不是MvxImageView来编写一些自定义处理(该控件可以继承或替换MvxImageView-它的代码很简单,并且很容易编写自己的自定义控件-请参阅中的自定义控件教程)
这个(相当混乱)问题中的一些信息可能有助于-

<Mvx.MvxImageView
  android:id="@+id/BookImageView"
  android:layout_width="80dp"
  android:layout_height="80dp"
  android:padding="8dp"
  android:src="@drawable/icon"
  local:MvxBind="ImageUrl AmazonImageUrl"
  />