Customizing OpenFileDialog in .Net

2019-01-26 10:13发布

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.

3条回答
Root(大扎)
2楼-- · 2019-01-26 10:27

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.

查看更多
冷血范
3楼-- · 2019-01-26 10:35

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.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-26 10:39

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.

查看更多
登录 后发表回答