简体   繁体   English

Microsoft.Win32.OpenFileDialog:取消时保存文件路径

[英]Microsoft.Win32.OpenFileDialog: save file path on cancel

The default Microsoft Office 2010 behavior for persisting the file path of the Open File dialog seems to return to the last place it had been navigated. 用于保留“打开文件”对话框的文件路径的默认Microsoft Office 2010行为似乎返回到其上次浏览的位置。

  • Open Microsoft Word 2010. 打开Microsoft Word 2010。
  • Press Ctrl+O. 按Ctrl + O。
  • The OpenFileDialog opens to, say, C:\\Temp\\ . OpenFileDialog打开,例如, C:\\Temp\\
  • Navigate through the file tree to C:\\Users\\mike\\Documents\\ . 浏览文件树到C:\\Users\\mike\\Documents\\ Don't select a file, and cancel the operation. 不要选择文件,然后取消操作。
  • Press Ctrl+O again. 再次按Ctrl + O。
  • The dialog will open to the C:\\Users\\mike\\Documents\\ directory. 对话框将打开到C:\\Users\\mike\\Documents\\目录。

I'd like to duplicate this behavior in my WPF application. 我想在WPF应用程序中复制此行为。 However the Microsoft.Win32.OpenFileDialog class doesn't seem to have a way to do this. 但是, Microsoft.Win32.OpenFileDialog类似乎没有执行此操作的方法。 The dialog returns false if Cancel was pressed (as advertised), but the FileName property doesn't get set if this is the case, and it appears to be impossible to capture the directory. 如果按“取消”(如广告所示),对话框将返回false ,但是在这种情况下,不会设置FileName属性,并且似乎无法捕获该目录。

Any suggestions for how I can do this? 关于如何执行此操作的任何建议?

Thanks to everyone who responded. 感谢大家的回应。 The answer appears to be that there is no answer. 答案似乎是没有答案。

Thanks to Jim Mischel for this link in the comments, which may provide a start: stackoverflow.com/q/4106120/56778 感谢吉姆·米歇尔(Jim Mischel)在评论中提供此链接,该链接可能会提供一个开始: stackoverflow.com/q/4106120/56778

Also to Hans Passant for his comment 'You'll have to get to the IFileDialogEvents. 还要感谢Hans Passant的评论“您必须进入IFileDialogEvents。 It isn't entirely impossible but you'll get no help from WPF.' 这并非完全不可能,但是WPF不会为您提供任何帮助。

I have a deadline for which this feature isn't critical, so I'm abandoning this for now. 我有一个截止日期,此功能并不重要,因此我暂时放弃此功能。 If I ever come up with a solution I'll post it here. 如果我提出解决方案,请在此处发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM