This is the fourth (and last) part in a series about how to get the latest look and feel for your WPF application, the previous parts are:
In part 3 of this series we’ve set a manifest file and almost solved our problem – we finally got rid of the Windows 2000 style dialogs and moved to XP, but we still haven’t got Vista style file open and save dialogs.
The problem is again backward compatibility, the Windows file dialogs are customizable and when an application customizes a dialog Windows will helpfully use the version of the dialog supported by the application in order not to break the customizations.
You probably didn’t customize the file dialogs but WPF (as well as WinForms) always tell Windows they customized the dialog.
All you have to do now is to bypass the FileOpenDialog and FileSaveDialog completely and use the Windows APIs directly – this is easier than it sounds – you basically have two options, you can find the Vista bridge sample on MSDN, this sample contains all the code needed to use and customize the Vista file dialogs (there is a lot of code there), on the other hand, you can use PInvoke to call the old simple APIs and as long as you don’t try to customize the dialog you will always get the latest version.
Download the code
The zip files contain classes that are mostly a drop in replacements for the WPF classes, the code is straight forward interop code that calls the GetOpenFileName or GetSaveFileName Windows functions, the only tricky part is that those functions sometimes return string with embedded nulls, I’ll explain how to deal with this in a future post.
posted @ Tuesday, July 15, 2008 4:26 PM