I have an MonoTouch project using MvvmCross. I am at the point where I could get my core project code compiling (with quite a bit of effort), and now I am creating the views for iOS. Running the latest stable releases of Xamarin tools, as well as MvvmCross. Also, I am running against iOS7 SDK with XCode 5 installed.
To start off I created a very basic view with a text field binding to my main view model. The relevant code in the view is as follows:
[Register("MainView")]
public partial class MainView : MvxViewController
{
public override void ViewDidLoad()
{
View = new UIView { BackgroundColor = UIColor.White };
base.ViewDidLoad();
var uiTextField = new UITextField(new RectangleF(0, 100, 320, 100));
Add(uiTextField);
this.CreateBinding(uiTextField).To<MainViewModel>(vm => vm.IsDebug).Apply();
}
}
The binding however throws a NullReference exception with the following stack trace:
System.NullReferenceException: Object reference not set to an instance of an object
at Cirrious.MvvmCross.Binding.BindingContext.MvxBaseFluentBindingDescription1[MonoTouch.UIKit.UITextField].SourcePropertyPath[MainViewModel] (System.Linq.Expressions.Expression
1 sourceProperty) [0x00000] in :0
at Cirrious.MvvmCross.Binding.BindingContext.MvxFluentBindingDescription1[MonoTouch.UIKit.UITextField].To[MainViewModel] (System.Linq.Expressions.Expression
1 sourceProperty) [0x00000] in :0
at ProjectX.Views.MainView.ViewDidLoad () [0x000a4] in /Users/jerriepelser/Development/1degree Software/ProjectX/Source/ProjectX.MonoTouch/Views/MainView.cs:26
at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:129
at ProjectX.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0003c] in /Users/jerriepelser/Development/1degree Software/ProjectX/Source/ProjectX.MonoTouch/AppDelegate.cs:27
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at ProjectX.Application.Main (System.String[] args) [0x00008] in /Users/jerriepelser/Development/1degree Software/ProjectX/Source/ProjectX.MonoTouch/Main.cs:16
If I set a breakpoint before the binding I can confirm that the ViewModel is set correctly on the base MvxViewController class, so it is not a problem with the ViewModel not being set.
I also tried the following way of doing the data binding:
var set = this.CreateBindingSet<MainView, MainViewModel> ();
set.Bind (uiTextField).To (vm => vm.IsDebug);
set.Apply ();
Still get a NullReference exception, but with the following stack trace:
System.NullReferenceException: Object reference not set to an instance of an object
at Cirrious.MvvmCross.Binding.BindingContext.MvxBaseFluentBindingDescription1[MonoTouch.UIKit.UITextField].SourcePropertyPath[MainViewModel] (System.Linq.Expressions.Expression
1 sourceProperty) [0x00000] in :0
at Cirrious.MvvmCross.Binding.BindingContext.MvxFluentBindingDescription2[MonoTouch.UIKit.UITextField,OneLove.Core.ViewModels.MainViewModel].To (System.Linq.Expressions.Expression
1 sourceProperty) [0x00000] in :0
at OneLove.Views.MainView.ViewDidLoad () [0x000a6] in /Users/jerriepelser/Development/1degree Software/OneLove/Source/OneLove.MonoTouch/Views/MainView.cs:29
at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:129
at OneLove.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0003c] in /Users/jerriepelser/Development/1degree Software/OneLove/Source/OneLove.MonoTouch/AppDelegate.cs:27
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at OneLove.Application.Main (System.String[] args) [0x00008] in /Users/jerriepelser/Development/1degree Software/OneLove/Source/OneLove.MonoTouch/Main.cs:16
Looking at the MvvmCross debug output gives me no hint as to what is wrong. Any ideas?