/// <summary> /// Cancels the editing of the data, but also closes the view model in the same call. /// </summary> /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> public static async Task <bool> CancelAndCloseViewModelAsync(this IViewModel viewModel) { Argument.IsNotNull("viewModel", viewModel); var result = await viewModel.CancelViewModelAsync(); if (result) { await viewModel.CloseViewModelAsync(false); } return(result); }
/// <summary> /// Cancels the editing of the data, but also closes the view model in the same call. /// </summary> /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> public static async Task <bool> CancelAndCloseViewModelAsync(this IViewModel viewModel) { Argument.IsNotNull("viewModel", viewModel); var viewModelBase = viewModel as ViewModelBase; if (viewModelBase != null) { var exitAfterBlock = false; if (viewModelBase.IsCanceling) { exitAfterBlock = true; if (!await viewModelBase.AwaitCancelingAsync()) { return(false); } } if (viewModelBase.IsClosing) { exitAfterBlock = true; await viewModelBase.AwaitClosingAsync(); } if (exitAfterBlock) { return(true); } } var result = await viewModel.CancelViewModelAsync(); if (result) { await viewModel.CloseViewModelAsync(false); } return(result); }