I am working on a wpf application and in that i am using file open dialog and i am facing a small problem. The problem is when i am at the file open dialog and if i click the parent window then the file dialog disappers. I dont want this to happen. I am using a helper class for the file open dialog and here is the code for it
using System;
using System.IO;
using System.Windows.Forms;
namespace MOAA.Infrastructure.Helpers
{
public static class DialogHelper
{
public static string ImportFileDialog(string fileNameWithPath)
{
var dialog = new OpenFileDialog()
{
FileName = fileNameWithPath ?? string.Empty,
InitialDirectory = fileNameWithPath != null ?
Path.GetDirectoryName(fileNameWithPath) : AppDomain.CurrentDomain.BaseDirectory,
};
var dialogStatus = dialog.ShowDialog();
if (dialogStatus == true)
{
return dialog.FileName;
}
return null;
}
}
}
调用ShowDialog()时需要指定父窗口:
var dialogStatus = dialog.ShowDialog(System.Windows.Application.Current.MainWindow);
Updated
You are using window dialog, so you might do some more works by wrapping it into a WPF view or window. Then, set owner for WPF control
wpfDialog.Owner = System.Windows.Application.Current.MainWindow;
This is how can you wrap it:
http://manfredlange.blogspot.com/2009/04/openfiledialog-in-net-on-vista.html
Hope it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.