views:

82

answers:

6

Hi,

I develop WPF4 application and in my app I need to let user to select a folder where aplication will store something (files, generated reports etc.).

My requirements:

— Ability to see standard folder tree

— Ability to select folder

— WPF look & feel, thid dialog must looks like part of modern application designed for Windows Vista/7 and not Windows 2000 or even Win9x.

As I understood, till 2010 (.Net 4.0) there is no standard folder dialog, but may be there is some changes in version 4.0?

Or all what rest to do is use old-scholl WinForms dialog? If it's the only way to do what I need so, how to make it closer to Vista/7 style and not Win9x?

On some formus I saw implementation of such dialogs but with old ugly icons a la Windows 95. It really doesn't look nice.

Thanks.

A: 

You will have to use P/Invokes and a few classes to get the Windows folder selection dialog.
There is a library for that, but for WinForms.

If you want, I can give you the link.

Here it is: http://www.codeproject.com/KB/vista/VistaControls.aspx?msg=3558360#xx3558360xx

Vercas
+2  A: 

Microsoft.Win32.OpenFileDialog is the standard dialog that any application on Windows uses. Your user won't be surprised by its appearance when you use WPF in .NET 4.0

The dialog was altered in Vista. WPF in .NET 3.0 and 3.5 still used the legacy dialog but that was fixed in .NET 4.0. I can only guess that you started this thread because you are seeing that old dialog. Which probably means you're actually running a program that is targeting 3.5. Yes, the Winforms wrapper did get the upgrade and shows the Vista version. System.Windows.Forms.OpenFileDialog class, you'll need to add a reference to System.Windows.Forms.

Hans Passant
A: 

Only such dialog is FileDialog. Its part of WinForms, but its actualy only wrapper around WinAPI standard OS file dialog. And I dont think it is ugly, its actualy part of OS, so it looks like OS it is run on.

Other way, there is nothing to help you with. You either need to look for 3rd party implementation, either free (and I dont think there are any good) or paid.

Euphoric
A: 

use OpenFileDialog

saurabh
+1  A: 

You can use the FolderBrowserDialog from WinForms. See this question on how to use in in WPF.

svick
+1  A: 

I wrote about it on my blog a long time ago, WPF's support for common file dialogs is really bad (or at least is was in 3.5 I didn't check in version 4) - but it's easy to work around it.

You need to add the correct manifest to your application - that will give you a modern style message boxes and folder browser (WinForms FolderBrowserDialog) but not WPF file open/save dialogs, this is described in those 3 posts (if you don't care about the explanation and only want the solution go directly to the 3rd):

Fortunately, the open/save dialogs are very thin wrappers around the Win32 API that is easy to call with the right flags to get the Vista/7 style (after setting the manifest)

Nir