Esempio n. 1
0
        /// <summary>
        /// Show a Common Win32 Dialog but with workaround for special case when
        /// shown from an already modal dialog.  Without woraround the CommonDialog
        /// gets shown as a modeless dialog.
        /// http://social.msdn.microsoft.com/Forums/en/wpf/thread/48ac4e21-ee16-4e64-b883-98b6c99ee1fa </summary>
        /// <param name="dialog">CommonDialog to show</param>
        /// <returns>Dialog result</returns>
        public static bool?ShowCommonDialogWorkaround(this CommonDialog dialog)
        {
            var  mainWindow    = Application.Current.MainWindow;
            var  currentWindow = DialogUtils.GetActiveWindow();
            bool?result;

            try
            {
                Application.Current.MainWindow = currentWindow;
                HookWindowActivatedEvents();
                _isDialogOpen = true;
                result        = dialog.ShowDialog();
            }
            finally
            {
                _isDialogOpen = false;
                UnhookWindowsActivatedEvents();
                Application.Current.MainWindow = mainWindow;
            }

            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// Show specified dialog, setting its owner to the active window</summary>
 /// <param name="dialog">Dialog to display</param>
 /// <returns>Nullable Boolean signifying how window was closed by user</returns>
 public static bool?ShowParentedDialog(this Window dialog)
 {
     dialog.Owner = DialogUtils.GetActiveWindow();
     return(dialog.ShowDialog());
 }
Esempio n. 3
0
 /// <summary>
 /// Extension method to show specified dialog, setting its owner to the active window</summary>
 /// <param name="dialog">Dialog to display</param>
 public static void ShowParented(this Window dialog)
 {
     dialog.Owner = DialogUtils.GetActiveWindow();
     dialog.Show();
 }
Esempio n. 4
0
        // Implements interactive portions of Find(), but is called from a separate thread to
        //  avoid recursion due to the dialog boxes.
        private static bool?QueryUser(Uri uri, Uri suggestedUri, out Uri newUri, SelectFileFilterOptions options)
        {
            // If the user cancels a sub-dialog box, reopen the first dialog box.
            while (true)
            {
                // Ask the user what we should do.
                // There are a two fewer options and slightly reorganized dialog box if there
                //  is no suggested replacement for the missing file.
                var vm = new FindFileDialogViewModel()
                {
                    Action        = s_lastAction,
                    OriginalPath  = uri.LocalPath,
                    SuggestedPath = suggestedUri != null ? suggestedUri.LocalPath : null,
                };

                bool?res = DialogUtils.ShowDialogWithViewModel <FindFileDialog>(vm);

                s_lastAction = res == false ? FindFileAction.Quit : vm.Action;

                switch (s_lastAction)
                {
                case FindFileAction.AcceptSuggestion:
                    newUri = suggestedUri;
                    return(true);

                case FindFileAction.AcceptAllSuggestions:
                    newUri = suggestedUri;
                    return(true);

                case FindFileAction.SearchDirectory:
                    if (SearchForFile(uri, out newUri, true))
                    {
                        return(true);
                    }
                    continue;

                case FindFileAction.SearchDirectoryForAll:
                    if (SearchForFile(uri, out newUri, false))
                    {
                        return(true);
                    }
                    continue;

                case FindFileAction.UserSpecify:
                    if (UserFindFile(uri, out newUri, options))
                    {
                        return(true);
                    }
                    continue;

                case FindFileAction.Ignore:
                    newUri = uri;
                    return(false);

                case FindFileAction.IgnoreAll:
                    newUri = uri;
                    return(false);

                case FindFileAction.Quit:
                    newUri = uri;
                    return(null);
                }

                throw new InvalidOperationException("unhandled FindFileAction enum");
            }
        }