Exemplo n.º 1
0
        /// <summary>
        ///   Asynchronously navigates to an instance of the provided ViewModel type. The navigation will be cancelled if
        ///   the current active ViewModel cannot be closed or the target type is not authorized.
        /// </summary>
        /// <param name="prepare"> An action to initialize the target ViewModel before it is activated. </param>
        /// <typeparam name="T"> The target ViewModel type. </typeparam>
        /// <returns> A <see cref="Task" /> to await completion. </returns>
        public Task NavigateToAsync <T>(Action <T> prepare)
        {
            if (prepare == null)
            {
                throw new ArgumentNullException("prepare");
            }

            return(NavigateToAsync <T>(viewModel =>
            {
                prepare(viewModel);
                return TaskFns.FromResult(true);
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Determines if the target ViewModel type is authorized.
        /// </summary>
        /// <param name="viewModelType"> The target ViewModel type. </param>
        /// <returns> Return true if the target type is authorized. </returns>
        private Task <bool> AuthorizeTargetAsync(Type viewModelType)
        {
            if (viewModelType == null)
            {
                throw new ArgumentNullException("viewModelType");
            }

            if (_configuration.TargetGuard != null)
            {
                return(_configuration.TargetGuard(viewModelType));
            }

            return(TaskFns.FromResult(true));
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Determines if the target ViewModel type is authorized.
        /// </summary>
        /// <param name="viewModelType"> The target ViewModel type. </param>
        /// <param name="contractName">The target ViewModel contract name.</param>
        /// <returns> Return true if the target type is authorized. </returns>
        private Task <bool> AuthorizeTargetAsync(Type viewModelType, string contractName)
        {
            if (viewModelType == null && string.IsNullOrEmpty(contractName))
            {
                throw new ArgumentNullException();
            }

            if (_configuration.TargetGuard != null)
            {
                return(_configuration.TargetGuard(viewModelType, contractName));
            }

            return(TaskFns.FromResult(true));
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Asynchronously navigates to an instance of the provided ViewModel type. The navigation will be cancelled if
        ///   the current active ViewModel cannot be closed or the target type is not authorized.
        /// </summary>
        /// <param name="viewModelType"> The target ViewModel type. </param>
        /// <param name="prepare"> An action to initialize the target ViewModel before it is activated. </param>
        /// <returns> A <see cref="Task" /> to await completion. </returns>
        public Task NavigateToAsync(Type viewModelType, Action <object> prepare)
        {
            if (viewModelType == null)
            {
                throw new ArgumentNullException("viewModelType");
            }
            if (prepare == null)
            {
                throw new ArgumentNullException("prepare");
            }

            return(NavigateToAsync(viewModelType, viewModel =>
            {
                prepare(viewModel);
                return TaskFns.FromResult(true);
            }));
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Asynchronously navigates to a ViewModel instance that matches the specified name and type.
        ///   The navigation will be cancelled if the current active ViewModel cannot be closed or the target type is not authorized.
        /// </summary>
        /// <param name="viewModelType"> The type to match. </param>
        /// <param name="contractName"> The name to match. </param>
        /// <param name="prepare"> An action to initialize the target ViewModel before it is activated. </param>
        /// <returns> A <see cref="Task" /> to await completion. </returns>
        /// <remarks>
        ///   Not available in Windows 8 Store apps.
        /// </remarks>
        public Task NavigateToAsync(Type viewModelType, string contractName, Action <object> prepare)
        {
            if (viewModelType == null && string.IsNullOrEmpty(contractName))
            {
                throw new ArgumentNullException();
            }
            if (prepare == null)
            {
                throw new ArgumentNullException("prepare");
            }

            return(NavigateToAsync(viewModelType, contractName, viewModel =>
            {
                prepare(viewModel);
                return TaskFns.FromResult(true);
            }));
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Determines if the active ViewModel can be closed.
        /// </summary>
        /// <returns> Returns true if the active ViewModel can be closed. </returns>
        private Task <bool> CanCloseAsync()
        {
            if (ActiveViewModel == null)
            {
                return(TaskFns.FromResult(true));
            }

            if (_configuration.ActiveItemGuard != null)
            {
                return(_configuration.ActiveItemGuard(ActiveViewModel));
            }

            var closeGuard = ActiveViewModel as IGuardClose;

            if (closeGuard != null)
            {
                return(TaskFns.FromCallbackAction <bool>(closeGuard.CanClose));
            }

            return(TaskFns.FromResult(true));
        }
Exemplo n.º 7
0
 /// <summary>
 ///   Provides an opportunity to perform asynchronous configuration at runtime.
 /// </summary>
 protected virtual Task StartRuntimeAsync()
 {
     return(TaskFns.FromResult(true));
 }