Пример #1
0
        public virtual async Task <TResult> Navigate <TParameter, TResult>(IMvxViewModel <TParameter, TResult> viewModel, TParameter param, IMvxBundle presentationBundle = null)
            where TParameter : class
            where TResult : class
        {
            RunViewModelLifecycle(viewModel);
            var request = new MvxViewModelInstanceRequest(viewModel)
            {
                PresentationValues = presentationBundle?.SafeGetData()
            };

            var args = new NavigateEventArgs(viewModel);

            OnBeforeNavigate(this, args);

            var tcs = new TaskCompletionSource <TResult>();

            viewModel.SetClose(tcs);

            ViewDispatcher.ShowViewModel(request);
            await viewModel.Initialize(param);

            OnAfterNavigate(this, args);

            try
            {
                return(await tcs.Task);
            }
            catch
            {
                return(default(TResult));
            }
        }