I have a property that is of type DateTime that I would like to bind to a viewmodel. When I bind the property I am getting and error stating that the binding type must be a reference type. How can I bind this property to my viewmodel and be notified of it's changes?
Specifically, the code that is causing the compiler error looks like this:
set.Bind (StartDate).To (vm => vm.StartDate);
Here is the property on the view.
public static DateTime StartDate { get; set; }
The general pattern for Fluent binding is:
set.Bind (target).For(v => v.TargetProperty).To (vm => vm.SourceProperty);
This binds the TargetProperty
of target
to the SourceProperty
of the source DataContext (normally the ViewModel).
When For
is omitted, then MvvmCross looks up a default property.
In your code, you are trying to bind the default property of the current StartDate
to the ViewModel's StartDate
. I suspect what you wanted instead was:
set.Bind(this).For(v => v.StartDate).To(vm => vm.StartDate);
For more on fluent data-binding syntax, please see the wiki http://github.com/mvvmcross/mvvmcross/wiki