选择文件夹对话框WPF对话框、文件夹、WPF

2023-09-02 11:49:52 作者:下個路口說再見

我开发一个WPF4应用程序,并在我的应用程序,我需要让用户选择一个文件夹的应用程序将存储的东西(文件,生成报表等)。

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

我的要求:

能够看到标准的文件夹树

Ability to see the standard folder tree

能够选择一个文件夹

WPF的外观和放大器;感觉,这种对话必须看起来像/ 7,而不是专为Windows Vista中的Windows 2000,甚至Win9x的现代应用程序的一部分。

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

据我了解,到2010年(.NET 4.0)不会有一个标准的文件夹对话框,但也许也有在4.0版本的一些变化?

As I understand, until 2010 (.Net 4.0) there won't be a standard folder dialog, but maybe there are some changes in version 4.0?

或者什么都剩下要做的就是用老派的WinForms对话框?如果它是做什么,我需要的唯一途径,我怎样才能使之更贴近Vista / 7的风格,而不是Win9x的?

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

在一些论坛上,我看到了这样的对话,但是与老变丑图标点菜Windows 95中执行这真的没有好看。

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

推荐答案

我写了一篇关于它在我的博客很久以前,WPF的共同文件对话框的支持是非常糟糕的(或至少是在3.5我没有检查4)版本 - 但它很容易解决它

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.

您需要正确的清单添加到您的应用程序 - 这会给你一个现代风格的消息框和文件夹的浏览器(的WinForms的FolderBrowserDialog),而不是WPF文件打开/保存对话框,这是在这3个职位描述(如果你不在意的解释,只想解决方案直接进入第3):

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):

Why我是越来越老样式文件对话框和消息框与WPF Will设置清单解决我的WPF消息框样式的问题? The应用程序清单所需的XP和Vista风格文件对话框和消息框与WPF Why am I Getting Old Style File Dialogs and Message Boxes with WPF Will Setting a Manifest Solve My WPF Message Box Style Problems? The Application Manifest Needed for XP and Vista Style File Dialogs and Message Boxes with WPF

幸运的是,打开/保存对话框都是围绕在Win32 API,很容易用正确的标志打电话来获得Vista / 7的风格(设置清单后)非常薄的包装

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)

Vista风格的打开和保存对话框与WPF(不使用Vista的桥样品)