Under .Droid have the following fragment:
public class DigestItemFragment : MvxFragment<DigestItemViewModel>
And within this, I've setup a binding for a programmatically created button.
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
this.EnsureBindingContextIsSet(savedInstanceState);
View view = this.BindingInflate(Resource.Layout.DigestItemFragment, null);
LinearLayout ls = view.FindViewById<LinearLayout>(Resource.Id.lakeside);
Button btn = new Button(container.Context);
string buttonText = "Get Down";
btn.SetHeight(100);
btn.SetWidth(300);
btn.SetText(buttonText.ToCharArray(), 0, buttonText.Length);
btn.SetBackgroundColor(Color.Gray);
btn.SetPadding(20, 20, 20, 20);
ls.AddView(btn);
var owner = this as IMvxBindingContextOwner;
var set = owner.CreateBindingSet<IMvxBindingContextOwner, DigestItemViewModel>();
set.Bind(btn)
.To(vm => vm.TimeSlotButtonOkCommand)
.WithFallback(btn);
set.Apply();
return view;
}
When the button is clicked, I can break on the call to the TimeSlotButtonOkCommand within the DigestItemViewModel, however, all the property values for the view model seem to be null.
A possible reason for this problem may be in how I created the binding set, by using IMvxBindingContextOwner rather than DigestItemFragment (see following code snippet), but sadly I've been unable to figure out how to use DigestItemFragment when creating the binding set.
var set = owner.CreateBindingSet<IMvxBindingContextOwner, DigestItemViewModel>();
Any ideas on what I have done wrong and why the DigestItemViewModel properties are all set to null within the TimeSlotButtonOkCommand?