我尝试将ViewModel中的IBitmap绑定到AndroidActivity中的ImageView。基本绑定不起作用,要求我注册
IBindingTypeConverter
为此:
class BitmapToImageViewConverter : IBindingTypeConverter
{
public int GetAffinityForObjects(Type fromType, Type toType)
{
return (fromType == typeof (IBitmap) && toType == typeof (ImageView)) ? 2 : 0;
}
public bool TryConvert(object from, Type toType, object conversionHint, out object result)
{
if (from == null)
{
result = null;
return false;
}
Drawable drawable = ((IBitmap) from).ToNative();
ImageView test = new ImageView(WeatherApp.AppContext);
test.SetImageDrawable(drawable);
result = test;
return true;
}
}
那没用。所以我尝试在OneWayBind中“转换”它,如下所示:
this.OneWayBind(this.ViewModel, vm => vm.WeatherIcon, v => v.weatherImageView.Drawable, v => v.ToNative());
但这也不起作用。我对ReactiveUI还是个新手,所以稍微提示一下就好了。