コード例 #1
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);
        }
コード例 #2
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);
 }