Ejemplo n.º 1
0
        private void CompleteClose()
        {
            INavigationContext context = CreateCloseContext();

            OnClosed(_closeParameter, context);

            bool?result          = null;
            var  operationResult = ViewModel as IHasOperationResult;

            if (operationResult != null)
            {
                result = operationResult.OperationResult;
            }
            OperationCallbackManager.SetResult(ViewModel,
                                               OperationResult.CreateResult(OperationType.WindowNavigation, ViewModel, result, context));

            _closeParameter = null;
            _shouldClose    = false;
            _isOpen         = false;
            TView view = View;

            if (view == null)
            {
                return;
            }
            ThreadManager.InvokeOnUiThreadAsync(() =>
            {
                CleanupView(view);
                _viewManager
                .CleanupViewAsync(ViewModel)
                .WithTaskExceptionHandler(ViewModel);
            });
            View = null;
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Tries to close view-model.
 /// </summary>
 /// <param name="parameter">The specified parameter, if any.</param>
 /// <returns>An instance of task with result.</returns>
 public Task <bool> CloseAsync(object parameter)
 {
     if (!IsOpen)
     {
         throw ExceptionManager.WindowClosed();
     }
     IsClosing       = true;
     _closeParameter = parameter;
     return(OnClosing(parameter)
            .TryExecuteSynchronously(task =>
     {
         try
         {
             if (task.Result)
             {
                 CloseViewImmediate();
             }
             return task.Result;
         }
         catch (Exception e)
         {
             OperationCallbackManager.SetResult(ViewModel,
                                                OperationResult.CreateErrorResult <bool?>(OperationType.WindowNavigation, ViewModel, e,
                                                                                          CreateCloseContext()));
             throw;
         }
         finally
         {
             IsClosing = false;
         }
     }));
 }
Ejemplo n.º 3
0
        public Task ShowAsync(IOperationCallback callback, IDataContext context)
        {
            ViewModel.NotBeDisposed();
            if (IsOpen)
            {
                throw ExceptionManager.WindowOpened();
            }
            var tcs = new TaskCompletionSource <object>();

            RaiseNavigating(context, NavigationMode.New)
            .TryExecuteSynchronously(task =>
            {
                try
                {
                    if (!task.Result)
                    {
                        tcs.TrySetCanceled();
                        if (callback != null)
                        {
                            callback.Invoke(OperationResult.CreateCancelResult <bool?>(OperationType.WindowNavigation, ViewModel, context));
                        }
                        return;
                    }
                    if (context == null)
                    {
                        context = DataContext.Empty;
                    }
                    if (callback != null)
                    {
                        OperationCallbackManager.Register(OperationType.WindowNavigation, ViewModel, callback, context);
                    }
                    _isOpen = true;
                    ShowInternal(context, tcs);
                }
                catch (Exception e)
                {
                    tcs.TrySetException(e);
                    if (callback != null)
                    {
                        callback.Invoke(OperationResult.CreateErrorResult <bool?>(OperationType.WindowNavigation, ViewModel, e, context));
                    }
                }
            });
            return(tcs.Task);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Shows the specified <see cref="IViewModel" />.
 /// </summary>
 /// <param name="callback">The specified callback, if any.</param>
 /// <param name="context">The specified context.</param>
 public void Show(IOperationCallback callback, IDataContext context)
 {
     ViewModel.NotBeDisposed();
     if (IsOpen)
     {
         throw ExceptionManager.WindowOpened();
     }
     _isOpen = true;
     if (context == null)
     {
         context = DataContext.Empty;
     }
     if (callback != null)
     {
         OperationCallbackManager.Register(OperationType.WindowNavigation, ViewModel, callback, context);
     }
     OnShow(context);
     ShowInternal(context);
 }