protected override void OnDestroy() { // 5. When the View disappears, dispose the bindings _simpleViewModel.PropertyChanged -= OnPropertyChanged; _simpleViewModel = null; base.OnDestroy(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); DataContext = new SimpleViewModel(); SetContentView(Resource.Layout.FourthPrinciplesView); var firstNameEdit = FindViewById<EditText>(Resource.Id.FirstNameEdit); var secondNameEdit = FindViewById<EditText>(Resource.Id.SecondNameEdit); var fullNameLabel = FindViewById<TextView>(Resource.Id.FullNameLabel); var set = this.CreateBindingSet<FourthPrinciplesView, SimpleViewModel>(); set.Bind(firstNameEdit).For(v => v.Text).To(vm => vm.FirstName).TwoWay(); set.Bind(secondNameEdit).For(v => v.Text).To(vm => vm.SecondName).TwoWay(); set.Bind(fullNameLabel).For(v => v.Text).To(vm => vm.FullName).OneWay(); set.Apply(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.FirstPrinciplesView); _simpleViewModel = new SimpleViewModel(); _firstNameEdit = FindViewById<EditText>(Resource.Id.FirstNameEdit); _secondNameEdit = FindViewById<EditText>(Resource.Id.SecondNameEdit); _fullNameLabel = FindViewById<TextView>(Resource.Id.FullNameLabel); // 1. Initially copy values ViewModel -> View SetInitialValues(); // 2. When ViewModel changes, update View _simpleViewModel.PropertyChanged += OnPropertyChanged; // 3. When View changes, update ViewModel SubscribeToUIChanges(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); DataContext = new SimpleViewModel(); SetContentView(Resource.Layout.ThirdPrinciplesView); }