OpenFileDialog 与 SaveFileDialog 该怎么用啊?

diffmaker 2017-03-02 01:35:33
Win10 64位,WPF中Microsoft.Win32.OpenFileDialog 与 Microsoft.Win32.SaveFileDialog遭遇错误

“System.AccessViolationException”类型的未经处理的异常在 PresentationFramework.dll 中发生
其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。



使用System.Windows.Forms.SaveFileDialog时,文件是保存上了,可保存的同时,WPF程序也关闭了。。。


好晕,大侠帮解释一下吗?

OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text Files|*.txt";
if (true == ofd.ShowDialog())
{
MessageBox.Show(File.ReadAllText(ofd.FileName));
}
...全文
269 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
diffmaker 2017-03-02
  • 打赏
  • 举报
回复
谢谢版主,辛苦
  • 打赏
  • 举报
回复
使用Microsoft.Win32下的的确没错,不过一般情况下,很少使用命令。
  • 打赏
  • 举报
回复
实践是验证真理的唯一标准,教科书也不一定教的都对呀。
diffmaker 2017-03-02
  • 打赏
  • 举报
回复
继续处理

    <Window.InputBindings>
        <KeyBinding Command="ApplicationCommands.Save" Key="F3" Modifiers="Control" />
    </Window.InputBindings>
绑定命令源后,不再报错了。。。教科书也坑啊
diffmaker 2017-03-02
  • 打赏
  • 举报
回复
我找到导致问题的原因了
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Open" Executed="OpenCmdExecuted" CanExecute="OpenCmdCanExecute"/>
        <CommandBinding Command="ApplicationCommands.Save" Executed="SaveCmdExecuted" CanExecute="SaveCmdCanExecute"/>
    </Window.CommandBindings>
这个ApplicationCommand惹的,如果直接在按钮事件上触发就不会有这种异常了

8,756

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧