SaveFileDialog OverwritePrompt无效

时间:2012-01-11 09:14:38

标签: wpf prism

在我的WPF应用程序中,如果我在保存文件时尝试覆盖现有文件,我希望收到覆盖提示通知。

这是保存文件的代码。 在savefiledialog选项中,我将Overwrite提示设置为true,但这无效。

var dialogOptions = new SaveFileDialogOptions { Filter = Resources.SaveFileDialogFilter, OverwritePrompt = true};

var result = dialogService.SaveFile(dialogOptions, null);

if (result == true)
{
// Save the file
}

DialogServices.cs

public bool? SaveFile(SaveFileDialogOptions options, Window owner)
{

return ShowDialog<SaveFileDialogOptions, SaveFileDialog>(options, owner);

}

static bool? ShowDialog<TDialogOptions, TDialog>(TDialogOptions options, Window owner)
            where TDialogOptions : FileDialogOptions, new()
            where TDialog : FileDialog, new()
{

var dialog = new TDialog();
            PropertyCopy<TDialog>.CopyFrom(options, dialog);
            var result = owner == null ? dialog.ShowDialog() : dialog.ShowDialog(owner);
            PropertyCopy<TDialogOptions>.CopyFrom(dialog, options);
            return result;

}

请回答,如果有人知道,为什么这不起作用。

提前致谢

1 个答案:

答案 0 :(得分:2)

SaveFileDialog.OverwritePrompt = false;