I am relatively new to Mvvm and MvvmCross. I've encountered a problem in iOS;
This is my delayed binding for my MvxTableViewCell-subclass, which I've put in AwakeFromNib:
this.DelayBind(() =>
{
var bindingSet = this.CreateBindingSet<MyTableViewCell, MyViewModel>();
bindingSet.Bind(myLabel).To(vm => vm.Name).WithConversion(debugvalueconverter, base.DataContext);
});
My debugvalueconverter looks like this:
public class DebugValueConverter : IMvxValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
System.Diagnostics.Debug.WriteLine("Converting debug: " + value);
if (parameter != null)
{
var vm = (MyViewModel)parameter;
System.Diagnostics.Debug.WriteLine("Converting debug - name from vm: " + vm.Name);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new NotImplementedException();
}
}
This generates some odd outputs when I'm starting to recycle cells when dragging in the tableview:
Converting debug: [Name from the cell that's appearing]
Converting debug - name from vm: [Name from an old cell which got recycled]
I.e. the DataContext doesn't seem to be set correctly in this case, BUT the name-property is set correctly. Why is this happening?
My problem is that I want to use a converter that will do some "advanced" calculations according to what's in a few properties of my ViewModel (I.e. my base.DataContext).
Is this a bug in MvvmCross or am I missing something? Why is not the DataContext set correctly here?
Thanks!