问题描述
我尝试,当我在 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 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)