예제 #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);
        }
예제 #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));
        }
예제 #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);
            }
        }
예제 #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);
        }