/// <inheritdoc/> Task <bool> IConductor.ActivateItemAsync(object item) { // Explicit interface implementation because this method is not really async. ActivateItem(item); return(TaskHelper.FromResult(true)); }
/// <inheritdoc/> public Task <bool> DeactivateItemAsync(object item, bool close) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (!item.Equals(Item)) { throw new ArgumentException("Item is not controlled by this conductor.", nameof(item)); } // This method might be called by the view model to close or hide the view. if (close) { var tcs = new TaskCompletionSource <bool>(); // ReSharper disable AccessToModifiedClosure ClosingEventHandler closingHandler = null; ClosedEventHandler closedHandler = null; closingHandler = (s, e) => { if (e.Cancel) { _view.Closing -= closingHandler; _view.Closed -= closedHandler; tcs.TrySetResult(false); } }; closedHandler = (s, e) => { _view.Closing -= closingHandler; _view.Closed -= closedHandler; tcs.TrySetResult(true); }; _view.Closing += closingHandler; _view.Closed += closedHandler; // ReSharper restore AccessToModifiedClosure _view.Close(); return(tcs.Task); } #if SILVERLIGHT || WINDOWS_PHONE throw new InvalidOperationException("Temporarily hiding a window or dialog in Silverlight is not supported."); #else _view.Hide(); (_viewModel as IActivatable)?.OnDeactivate(false); return(TaskHelper.FromResult(true)); #endif }
/// <inheritdoc/> public override Task <bool> CanCloseAsync() { var guardClose = Item as IGuardClose; return((guardClose != null) ? guardClose.CanCloseAsync() : TaskHelper.FromResult(true)); }
/// <inheritdoc/> public virtual Task <bool> CanCloseAsync() { return(TaskHelper.FromResult(true)); }