Exemplo n.º 1
0
        /// <summary>
        /// Showing a standard dialog as fallback.
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        private DialogResult ShowDialog(DialogViewModel vm)
        {
            var dialog = new ModernDialog
            {
                Title       = vm.Title,
                DataContext = vm
            };

            dialog.ShowDialog();
            switch (dialog.Result)
            {
            case DialogResult.OK:
                return(DialogResult.OK);

            case DialogResult.Cancel:
                return(DialogResult.Cancel);

            case DialogResult.Yes:
                return(DialogResult.Yes);

            case DialogResult.No:
                return(DialogResult.No);

            case DialogResult.None:
            default:
                return(DialogResult.None);
            }
        }
Exemplo n.º 2
0
        protected virtual DialogResult Show(DialogViewModel viewModel)
        {
            var result = Application.Current.Dispatcher.Invoke(
                () =>
            {
                var window = Application.Current.MainWindow as ModernWindow;
                if (window == null)
                {
                    return(DialogResult.None);
                }
                var dialog = new ModernPopup {
                    DataContext = viewModel
                };
                return(dialog.RunDialog(window, this, viewModel));
            }, DispatcherPriority.Background);

            return(result);
        }
Exemplo n.º 3
0
        internal DialogResult RunDialog(ModernWindow owner, IDialogHandler dialogHandler, DialogViewModel viewModel)
        {
            this.Result = null;
            var decorator = owner.AdornerDecorator;

            if (decorator == null || !owner.IsActive)
            {
                return(ShowDialog(viewModel));
            }
            AdornerLayer adornerLayer = decorator.AdornerLayer;
            var          uiElement    = decorator.Child;

            if (adornerLayer == null || uiElement == null)
            {
                return(ShowDialog(viewModel));
            }

            var adorner = new ContentAdorner(uiElement, this);

            adornerLayer.Add(adorner);

            while (this.Result == null)
            {
                DoEvents();
            }

            adornerLayer.Remove(adorner);
            return(this.Result.Value);
        }