gpt4 book ai didi

c# - WPF-保存文件对话框

转载 作者:可可西里 更新时间:2023-11-01 03:03:29 27 4
gpt4 key购买 nike

我在 WPF 中使用 SaveFileDialog 导出到用户选择的特定位置的 excel 文件。但是在 SaveFileDailog 打开和用户点击对话框上的 Cancel 按钮 之间,我收到另一个对话框,上面写着 “Do you want to save changes you made到 'Sheet1'?” 然后是 “Export completed” 而不是取消导出。

那么我该怎么做才能解决这个问题呢? WPF 中的任何内容,例如 'DialogResult' 是否与 winForms 中的相同?

最佳答案

如果用户保存,SaveFileDialog 将返回 true(ShowDialog 方法返回一个可为 null 的 bool 值),如果用户按下取消,则返回 false/null。下面是一个示例 MSDN入门代码:

// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();

// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
}

关于c# - WPF-保存文件对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8147574/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com