private async Task <object> ShowDialogWrapper(object dialog)
        {
            object     result     = null;
            DialogHost dialogHost = WPFDialogShower.GetActiveWindowDialogHost();

            if (dialogHost != null && !isDialogShown)
            {
                DialogClosingEventHandler onDialogClose = new DialogClosingEventHandler((sender, eventArgs) => { result = eventArgs.Parameter; });

                WPFDialogShower.isDialogShown = true;
                if (onDialogClose != null)
                {
                    dialogHost.DialogClosing += onDialogClose;
                }

                await dialogHost.ShowDialog(dialog);

                if (onDialogClose != null)
                {
                    dialogHost.DialogClosing -= onDialogClose;
                }
                WPFDialogShower.isDialogShown = false;
            }
            return(result);
        }
        public void CloseCurrent()
        {
            DialogHost dialogHost = WPFDialogShower.GetActiveWindowDialogHost();

            if (dialogHost != null)
            {
                dialogHost.IsOpen = false;
            }
        }
        private async Task <object> ShowDialogWrapper(object dialog, int timeout = 0)
        {
            object     result     = null;
            DialogHost dialogHost = WPFDialogShower.GetActiveWindowDialogHost();

            if (dialogHost != null && !isDialogShown)
            {
                DialogClosingEventHandler onDialogClose = new DialogClosingEventHandler((sender, eventArgs) => { result = eventArgs.Parameter; });

                WPFDialogShower.isDialogShown = true;
                if (onDialogClose != null)
                {
                    dialogHost.DialogClosing += onDialogClose;
                }

                try
                {
                    if (timeout > 0)
                    {
                        await dialogHost.ShowDialog(dialog, async delegate(object sender, DialogOpenedEventArgs args)
                        {
                            await Task.Delay(timeout);
                            args.Session.Close(false);
                        });
                    }
                    else
                    {
                        await dialogHost.ShowDialog(dialog);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }

                if (onDialogClose != null)
                {
                    dialogHost.DialogClosing -= onDialogClose;
                }
                WPFDialogShower.isDialogShown = false;
            }
            return(result);
        }
        private static DialogHost GetActiveWindowDialogHost()
        {
            if (WPFDialogShower.lastActiveWindow != null)
            {
                DialogHost dialog = WPFDialogShower.GetDialogHost(WPFDialogShower.lastActiveWindow);
                if (dialog != null)
                {
                    return(dialog);
                }
            }

            IEnumerable <LoadingWindowBase> windows = Application.Current.Windows.OfType <LoadingWindowBase>();

            if (windows.Count() > 0)
            {
                return(WPFDialogShower.GetDialogHost(windows.FirstOrDefault(x => x.IsActive)));
            }

            return(null);
        }