[已解决]由于某种原因,我的savefile对话框立即返回false [英] [Solved] For some reason my savefiledialog is instantly returning false

查看:96
本文介绍了[已解决]由于某种原因,我的savefile对话框立即返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码没有任何重大改变,但是由于某种原因,我的保存文件对话框现在闪烁打开,然后关闭,并且返回的显示对话框结果为false.它已经完美地工作了一段时间,但是现在它正在这样做.还有其他人看到过这样的东西吗?

My code hasn''t changed in any significant way, but for some reason my save file dialog now flickers open, then closes and the show dialog result returned is false. It was working flawlessly for some time, but now it is doing this. Has anyone else seen something like this?

<br />
<pre lang="cs">internal string BrowseForSaveAsDoc()<br />
        {<br />
            SaveFileDialog dlg = new SaveFileDialog();<br />
            dlg.CheckPathExists = true;<br />
            dlg.CheckFileExists = false;<br />
            dlg.DefaultExt = ".docx";<br />
            dlg.AddExtension = true;<br />
            dlg.Filter = "Word Documents (*.docx)|*.docx";<br />
            var res = dlg.ShowDialog();<br />
            if (res == true)<br />
                return dlg.FileName;<br />
            return "";<br />
        }</pre><br />
<br />


在if语句上设置断点时,我立即将res视为false.就在前几天,它运行得很完美.我的计算机上发生了什么时髦的事吗?

更新:
由OP自己解决.作为答案之一.


I instantly see res as false when I set a breakpoint on the if statement. It was working flawlessly just the other day. Is there something funky that happened to my computer or something?

UPDATE:
Solved by OP himself. Posted as one of the answers.

推荐答案

好,我知道发生了什么.执行show modal动作的按钮在wpf弹出控件内.我将弹出窗口修改为StaysOpen ="false".因此,弹出窗口会在失去焦点时隐藏(显示模态时),因此调用模态的上下文会被杀死,因此它会自行取消.
Ok I figured out what is happening. The button that executes the show modal actions is inside a wpf popup control. I modified the popup to StaysOpen="false". So the popup hides the moment it loses focus (when the modal shows up) and thus the context that called the modal is killed so it just cancels itself out.


旁注:不要不要写return "",请使用string.Empty(如果需要,请使用null).在所有情况下都应避免使用立即数常量(例如").

—SA
A side note: Don''t write return "", use string.Empty (or null if you wish). Avoid immediate constants (such as "") in all cases.

—SA


这篇关于[已解决]由于某种原因,我的savefile对话框立即返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆