private static bool UserFindFile(Uri uri, out Uri newUri, SelectFileFilterOptions options) { newUri = uri; var dlg = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, Multiselect = false, Title = string.Format( "Find or Replace {0}", Path.GetFileName(uri.LocalPath)) }; if (options == SelectFileFilterOptions.ExactMatch) { string fileName = Path.GetFileName(uri.LocalPath); dlg.Filter = fileName + "|" + fileName; } else if (options == SelectFileFilterOptions.ExtensionMatch) { string extension = Path.GetExtension(uri.LocalPath); dlg.Filter = extension + "|" + extension; } if (dlg.ShowDialog(DialogUtils.GetActiveWindow()) == true) { newUri = new Uri(dlg.FileName); s_localPathMap.Add(uri.LocalPath, newUri); return(true); } return(false); }
/// <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); }
/// <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(); }
/// <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()); }