我制作了一个 WPF 应用程序,您可以在其上打开一些 Open/SaveFileDialogs。在我的电脑上,它会记住我上次使用此类对话框时所在的目录,并在我打开另一个此类对话框时将其设置为初始目录。但在我同事的电脑上,它不记得了。
我使用的确切类是Microsoft.Win32.OpenFileDialog
. 我们都安装了WinXP。
这可能是什么原因造成的?
更新: 显然这个问题还没有解决。我发现它也发生在我的电脑上。我发现当我选择多个文件并单击打开或按回车时,它不会保存它所在的位置。但是当我只选择一个文件并打开时钟或按回车键(或双击它)时,它确实记住了位置。
这是代码:
public override void Execute(object parameter)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.DefaultExt = ".txt";
dialog.Filter = "Text files (.txt)|*.txt";
dialog.Multiselect = true;
dialog.Title = "Select a trace file";
// The documentation says ShowDialog always returns either true or false,
// so we get the value of the returned Nullable<bool> immediately to get
// rid of the Nullable<bool> type.
bool result = dialog.ShowDialog().Value;
if (result)
{
foreach (string fileName in dialog.FileNames)
{
traceFilesViewModel.TraceFileList.Add(fileName);
traceFilesViewModel.StatusBackground = Brushes.PeachPuff;
traceFilesViewModel.StatusForeground = Brushes.Red;
traceFilesViewModel.StatusText = "Trace files not loaded.";
}
}
}