private async void _onPropertyChanged(ActivateableViewModel oldVal, ActivateableViewModel newVal) { // this is only to support cases where the owner view model // changes the property without a proper call to Navigate // but when you do call navigate, it will have already happened // by the time we get here. // Note that when performed like this, the calls to this method // is not "awaited" so exceptions that occur here will not be caught await _ensureActivationState(oldVal, newVal); }
private async Task _ensureActivationState(ActivateableViewModel oldVm, ActivateableViewModel newVm) { if ((oldVm != null) && (oldVm.IsActive)) { await oldVm.Deactivate(); } if ((newVm != null) && (!newVm.IsActive)) { await newVm.Activate(); } }
public async Task Start(Region region, ActivateableViewModel parent, string propertyName) { Region = region; Parent = parent; Property = Parent.GetType().GetProperty(propertyName); Parent.Activated += (s, e) => _onParentActivated(); Parent.Deactivated += (s, e) => _onParentDeactivated(); Parent.Observe <ActivateableViewModel>(propertyName, this, _onPropertyChanged); if (Parent.IsActive) { _onParentActivated(); } var vm = _getViewModel(); if ((vm != null) && (!vm.IsActive)) { await vm.Activate(); } }
private void _setViewModel(ActivateableViewModel value) { Property.SetValue(Parent, value); }