Example #1
0
        private Window CreateView <TViewModel>(TViewModel viewModel)
        {
            IViewRegistration registration = GetRegistration(typeof(TViewModel));

            var window = registration.CreateView();

            window.DataContext = viewModel;
            window.Owner       = WindowUtil.GetActiveWindow();

            return(window);
        }
Example #2
0
        public MessageBoxResult Show(string messageBoxText,
                                     string caption                 = null,
                                     MessageBoxButton button        = MessageBoxButton.OK,
                                     MessageBoxImage icon           = MessageBoxImage.None,
                                     MessageBoxResult defaultResult = MessageBoxResult.None)
        {
            var owner = WindowUtil.GetActiveWindow();

            caption = caption ?? "";

            if (owner == null)
            {
                return(MessageBox.Show(messageBoxText, caption, button, icon, defaultResult));
            }

            return(MessageBox.Show(owner, messageBoxText, caption, button, icon, defaultResult));
        }
Example #3
0
        public void EditText(string text, string caption, string title, Action <string> setter, Func <string, bool> validate = null)
        {
            if (setter == null)
            {
                throw new ArgumentNullException(nameof(setter));
            }

            var viewModel = new TextEditDialogViewModel(text, caption, title, validate);

            var view = new TextEditDialogView()
            {
                DataContext = viewModel,
                Owner       = WindowUtil.GetActiveWindow()
            };

            if (view.ShowDialog() == true)
            {
                setter(viewModel.Text);
            }
        }
Example #4
0
        private FileDialogResult ShowDialog(FileDialog dialog, FileDialogOptions options)
        {
            if (dialog == null)
            {
                throw new ArgumentNullException(nameof(dialog));
            }

            if (options != null)
            {
                SetDialogProperties(dialog, options);
            }

            bool?result;

            //Try to get the active window
            var owner = WindowUtil.GetActiveWindow();

            if (owner == null)
            {
                result = dialog.ShowDialog();
            }
            else
            {
                result = dialog.ShowDialog(owner);
            }

            if (result == true)
            {
                return(new FileDialogResult()
                {
                    FileName = dialog.FileName,
                    FileNames = dialog.FileNames
                });
            }

            return(null);
        }