Beispiel #1
0
        public async Task <TResult> ShowDialogAsync <TResult>(BaseDialogViewModel <TResult> viewModel)
        {
            if (shell.IsDialogShown)
            {
                throw new InvalidOperationException("Other dialog is already shown.");
            }

            var tcs  = new TaskCompletionSource <TResult>();
            var view = GetView(viewModel.GetType());

            view.DataContext = viewModel;

            viewModel.RequestCloseCallback = r =>
            {
                shell.HideDialogAsync();
                tcs.TrySetResult(r);
            };

            try
            {
                shell.IsDialogShown = true;

                await shell.ShowDialogAsync(view);

                return(await tcs.Task);
            }
            finally
            {
                shell.IsDialogShown            = false;
                viewModel.RequestCloseCallback = null;
            }
        }
Beispiel #2
0
        private static async Task <object> ShowDialogInternal(BaseDialogViewModel vm)
        {
            var viewType = await FindView(vm.GetType());

            var view = Activator.CreateInstance(viewType) as UserControl;

            view.DataContext = vm;

            return(await DialogHost.Show(view, openedEventHandler : (sender, e) =>
            {
                vm.Close = e.Session.Close;
            }));
        }