public AdminViewModel() { Navigation.New = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(NewCallback), () => NewEnableCallback(NewEnable())); Navigation.Duplicate = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(DuplicateCallback), () => DuplicateEnableCallback(DuplicateEnable())); Navigation.Modify = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(ModifyCallback), () => ModifyEnableCallback(ModifyEnable())); Navigation.ReloadCurrent = new AwaitableDelegateCommand(() => RefreshModelInformation(Model.Id), () => ReloadCurrentEnable()); Navigation.Confirm = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(ConfirmCallback), () => ConfirmEnable()); Navigation.Cancel = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(CancelCallback), () => CancelEnable()); Model.ErrorsChanged += Model_ErrorsChanged; _backForwardNavigator = new ExtendedNavigator <int>(); SetUpNewNavigator(); ConfirmCancelLocker.LockStatusChanged += (s, e) => { Navigation.New.RaiseCanExecuteChanged(); Navigation.Duplicate.RaiseCanExecuteChanged(); Navigation.Modify.RaiseCanExecuteChanged(); Navigation.Confirm.RaiseCanExecuteChanged(); Navigation.Cancel.RaiseCanExecuteChanged(); }; NewRecordCancelLocker.LockStatusChanged += (s, e) => { Navigation.Confirm.RaiseCanExecuteChanged(); Navigation.Cancel.RaiseCanExecuteChanged(); }; OutsideModificationLocker.RequestLock(_modifyingToken); OutsideModificationLocker.LockStatusChanged += (s, e) => OnPropertyChanged(nameof(OutsideModificationAllowed)); }
/// <summary> /// Used to swap the <see cref="Navigation" /> that is used for the back, and forth logic. /// </summary> /// <param name="newNavigator">The new <see cref="Navigation" />.</param> /// <returns>Task for async use.</returns> public async Task SwapNavigator(IExtendedNavigator <int> newNavigator) { var oldValue = _backForwardNavigator; if (Perform.ReplaceIfDifferent(ref _backForwardNavigator, newNavigator, new ExtendedNavigator <int>()).WasSuccessful) { await BackForwardNavigatorSwapped(_backForwardNavigator, oldValue); } }
/// <summary> /// The logic used to swap the <see cref="Navigation" />. /// </summary> /// <param name="newValue">The new <see cref="Navigation" />.</param> /// <param name="oldValue">The old <see cref="Navigation" /></param> /// <returns>Task for async use.</returns> protected virtual async Task BackForwardNavigatorSwapped(IExtendedNavigator <int> newValue, IExtendedNavigator <int> oldValue) { if (oldValue != null) { await newValue.UpdateCurrentItem(oldValue.CurrentItem); oldValue.CurrentItemChangedCallback = null; } SetUpNewNavigator(); }