在 .Net 中自定义 OpenFileDialog
需要在 Windows XP 和 Windows Vista/7 中创建本机外观的自定义 .Net OpenFileDialog。向其中添加新控件等。有没有办法在.Net(特别是WPF)中自定义标准OpenFileDialog?我已经浏览过诸如 OpenFileDialogEx 之类的解决方案,但所有 WINAPI 挂钩的东西都是我不能接受。也许有人知道一种通过反射或其他方式提取本机对话框的方法? Windows Vista/7中原生的OpenFileDialog是如何实现的?是用WPF写的吗?提前致谢。
问候,帕维尔。
In need to create native looking customized .Net OpenFileDialog in Windows XP and Windows Vista/7. Add new controls to it, etc. Is there any way to customize standard OpenFileDialog in .Net (WPF specifically)? I've looked through the solutions like OpenFileDialogEx, but all that WINAPI hooking stuff is not acceptable for me. Maybe one knows a way to extract native dialogs via Reflection or something? How the native OpenFileDialog in Windows Vista/7 is implemented? Is it written in WPF? Thanks in advance.
Regards, Pavel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
习惯它,因为这就是它所需要的。 OpenFileDialog 不是用 WPF 编写的,该对话框在 Windows 中作为非托管代码存在。托管包装器在旧版本上使用 GetOpenFileName(),在当前版本上使用 IFileOpenDialog COM 接口。对于后一种情况,IFileDialogCustomize 接口被设计用于自定义对话框。
这些接口只能在 C++ 程序中轻松使用,这是 shell 编程的经典祸害。必须支持 XP 机器也是一个相当令人头疼的问题,实际上,您会陷入通过 GetOpenFileName() 的旧对话框中。这就是该代码项目的作用。
Get used to it because that what it takes. OpenFileDialog is not written in WPF, the dialog exists as unmanaged code inside Windows. The managed wrapper uses GetOpenFileName() on legacy versions, the IFileOpenDialog COM interface on current ones. For the latter one, the IFileDialogCustomize interface was designed to customize the dialog.
These interfaces are only easy to use from a C++ program, a classic scourge of shell programming. Having to support XP machines is a considerable headache as well, realistically you are stuck with the legacy dialog through GetOpenFileName(). Which is what that code project does.
Windows API 代码包 中有一个 OpenFileDialog 的包装器。它可以帮助您解决自己 P/调用它的许多困难。您可以从 WPF、Windows 窗体等任何地方使用它。
There is a wrapper for the OpenFileDialog in the Windows API Code Pack. It gets you around a lot of the difficulty of P/Invoking it yourself. You can use it from WPF, from Windows Forms, whatever.
您可以查看此 CodeProject 链接。
这是一种有趣的方式来创建您可能想要的任何文件对话框。作者还提供了 WPF 版本的链接以及针对 XP 编写的原始文章。
You might take a look at this CodeProject link.
It's an interesting way to create just about any file dialog you might want. And the author includes a link to a WPF version as well as the original article written with XP in mind.