MvxImageViewLoader绑定无法正常工作

时间:2013-06-24 11:02:05

标签: data-binding touch mvvmcross

我在非常简单的情况下使用 MvxImageViewLoader

ViewDidLoad

        var pnlBackImage = new UIImageView(new RectangleF(0, 0, pnlBack.Frame.Width, pnlBack.Frame.Height));
        Add(pnlBackImage);
        pnlBackImageLoader = new MvxImageViewLoader(() => pnlBackImage);

        ...

        set.Bind(pnlBackImageLoader).To(x => x.UserBackgroundUrl);

其中UserBackgroundUrl是公共字符串属性

但是在 set.Apply()上,我在日志和图片中看到以下内容未加载

2013-06-24 13:51:26.999 SPBTouch[446:21b03] MvxBind: Error:   2.78 Problem seen during binding execution for from UserBackgroundUrl to ImageUrl - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
      at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d9] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:236 
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00064] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoProperty.cs:353 
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/PropertyInfo.cs:93 
  at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0 
  at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (Boolean isAvailable, System.Object value) [0x00000] in <filename unknown>:0 
InnerException was NullReferenceException: Object reference not set to an instance of an object
      at Cirrious.MvvmCross.Binding.Views.MvxBaseImageViewLoader`1[MonoTouch.UIKit.UIImage].set_ImageUrl (System.String value) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000c0] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:228 

我甚至将图像加载器甚至图像面板定义为视图字段,但仍然没有运气。什么可能导致这个问题?

谢谢。

2 个答案:

答案 0 :(得分:6)

您列出的内部异常错误是:

  

NullReferenceException:未将对象引用设置为对象的实例         在Cirrious.MvvmCross.Binding.Views.MvxBaseImageViewLoader`1 [MonoTouch.UIKit.UIImage] .set_ImageUrl(System.String value)[0x00000] in:0

我猜这会导致NullReferenceException中的set

    public string ImageUrl
    {
        get { return _imageHelper.ImageUrl; }
        set { _imageHelper.ImageUrl = value; }
    }

如果_imageHelper为空

查看MvxBaseImageViewLoader.cs#L31如果显示此错误消息Unable to resolve the image helper - have you referenced and called EnsureLoaded on the DownloadCache plugin?

,就会发生这种情况

是否显示此错误消息?如果是这样,您的应用程序中是否加载了DownloadCache插件(以及它的依赖插件File)?


如果这没有帮助,请尝试比较您的应用,以便N + 1中的某些应用。几个N + 1个视频中涵盖了图像视图的成功使用 - http://mvvmcross.wordpress.com/ - 例如N = 2或N = 3

答案 1 :(得分:3)

按照MvvmCross CollectionView example上的教程,当我遇到本问题中提到的相同错误(异常)时,我来到这里。如果您错过了注册/安装插件,我发现您收到此错误。我通过安装以下插件解决了错误:

  

安装包MvvmCross.ITSparta.Plugin.DownloadCache

     

安装包MvvmCross.ITSparta.Plugin.File

安装这些插件后,会在UI项目(iOS / Android)中创建新文件,并注册这些插件。因此,您不会收到此错误。