DialogResult.OK on SaveFileDialog not work(SaveFileDialog 上的 DialogResult.OK 不起作用)
问题描述
我尝试,当我在 SaveFileDialog
中按保存时,我会做一些事情.我尝试修复,但总是有问题.
I try, when I press save in SaveFileDialog
I do something. I trying fix but always something wrong.
SaveFileDialog dlg2 = new SaveFileDialog();
dlg2.Filter = "xml | *.xml";
dlg2.DefaultExt = "xml";
dlg2.ShowDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
{....}
但我在 OK 上有错误 - 说:
But I have error on OK - which say:
错误:System.Nullable"不包含OK"的定义,并且找不到接受System.Nullable"类型的第一个参数的扩展方法OK"(您是否缺少 using 指令或程序集引用?)
我尝试用这段代码修复:
I try fix with this code:
DialogResult result = dlg2.ShowDialog(); //here is error again
if (result == DialogResult.OK)
{....}
现在错误出现在 DialogResult 上说:'System.Windows.Window.DialogResult' 是一个 'property' 但被用作一个 'type'
Now error is on DialogResult say: 'System.Windows.Window.DialogResult' is a 'property' but is used like a 'type'
推荐答案
我假设你指的是 WPF
而不是 Windows Form
这是使用 SaveFileDialog
I assume that you are referring to WPF
not Windows Form
Here is example of using SaveFileDialog
//configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; //default file name
dlg.DefaultExt = ".xml"; //default file extension
dlg.Filter = "XML documents (.xml)|*.xml"; //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;
}
其他示例:
在 WPF
中你必须处理 DialogResult
枚举和 Window.DialogResult
属性之间的冲突
In WPF
you have to handle conflict between DialogResult
Enumeration and Window.DialogResult
Property
尝试使用完全限定名称来引用枚举:
Try using fully qualified name to refer the enumeration:
System.Windows.Forms.DialogResult result = dlg2.ShowDialog();
if (result == DialogResult.OK)
{....}
这篇关于SaveFileDialog 上的 DialogResult.OK 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SaveFileDialog 上的 DialogResult.OK 不起作用


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01