问题描述
我尝试,当我保存在 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)
{....}
但是我有错误的确定 - 其中说:
But I have error on OK - which say:
错误:
'System.Nullable'不包含定义对于'OK',并且没有扩展方法'OK'接受类型'System.Nullable'的第一个参数可以找到(你缺少一个using指令或程序集引用?)
我尝试用这段代码修复:
I try fix with this code:
DialogResult result = dlg2.ShowDialog(); //here is error again
if (result == DialogResult.OK)
{....}
现在错误在DialogResult上说:
'System.Windows.Window.DialogResult'是一个'属性',但使用像'类型'
Now error is on DialogResult say:'System.Windows.Window.DialogResult' is a 'property' but is used like a 'type'
推荐答案
我假设你是指 WPF
不是 Windows窗体
以下是使用 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不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!