【发布时间】:2021-02-16 13:03:34
【问题描述】:
您好,我的应用程序使用一些OpenFileDialogs 进行文件选择。此外,我需要一个文件夹选择器,为此我使用了 CommonOpenFileDialog 和选项 IsFolderPicker = true。
现在,当我在应用程序中打开 OpenFileDialog 时,父窗口被锁定并且不能再使用,这正是我想要的行为。
但是当我使用CommonOpenFileDialog 时,我仍然可以访问父窗口并打开更多CommonOpenFileDialogs。
OpenFileDialog 是这样初始化的:
//init dialog
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Path.GetFullPath(SecondQPcrFilePath);
openFileDialog.CheckFileExists = true;
openFileDialog.CheckPathExists = true;
openFileDialog.Multiselect = false;
openFileDialog.ReadOnlyChecked = false;
openFileDialog.ShowReadOnly = false;
//show dialog
bool? dialogResult = openFileDialog.ShowDialog();
CommonOpenFileDialog 是这样的:
//is this mvvm conform?
Button senderButton = (Button)sender;
string clickedButton = senderButton.Name;
//init dialog
CommonOpenFileDialog openPathDialog = new CommonOpenFileDialog();
openPathDialog.IsFolderPicker = true;
openPathDialog.EnsurePathExists= true;
openPathDialog.Multiselect = false;
openPathDialog.EnsureFileExists = false;
openPathDialog.AllowNonFileSystemItems = true;
if(clickedButton == "limsOpenButton")
{
openPathDialog.InitialDirectory = Path.GetFullPath(LimsPath);
}
else if(clickedButton == "qpcrOpenButton")
{
openPathDialog.InitialDirectory = Path.GetFullPath(QpcrPath);
}
//show dialog
CommonFileDialogResult dialogResult = openPathDialog.ShowDialog();
有没有办法防止这种行为?普通对话框没有 Owner 或类似的属性。
【问题讨论】: