WPF是否具有本机文件对话框? [英] Does WPF have a native file dialog?

查看:103
本文介绍了WPF是否具有本机文件对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Windows.Controls下,我可以看到一个PrintDialog.但是,我似乎找不到本地的FileDialog.我是否需要创建对System.Windows.Forms的引用,或者还有另一种方法?

Under System.Windows.Controls, I can see a PrintDialog However, I can't seem to find a native FileDialog. Do I need to create a reference to System.Windows.Forms or is there another way?

推荐答案

WPF确实具有内置(尽管不是 native )文件对话框.具体来说,它们位于稍微出乎意料的Microsoft.Win32命名空间中(尽管仍然是WPF的一部分).请参见 OpenFileDialog

WPF does have built-in (although not native) file dialogs. Specifically, they are in the slightly unexpected Microsoft.Win32 namespace (although still part of WPF). See the OpenFileDialog and SaveFileDialog classes in particular.

但是请注意,这些类仅是Win32功能的包装,如父名称空间所建议的那样.但是,这确实意味着您不需要进行任何WinForms或Win32互操作,这使它使用起来更好一些.不幸的是,默认情况下,对话框是旧" Windows主题中的样式,并且您需要在app.manifest中进行细小的修改才能强制其使用新的对话框.

Do however note that these classes are only wrappers around the Win32 functionality, as the parent namespace suggests. It does however mean that you don't need to do any WinForms or Win32 interop, which makes it somewhat nicer to use. Unfortunately, the dialogs are by default style in the "old" Windows theme, and you need a small hack in app.manifest to force it to use the new one.

这篇关于WPF是否具有本机文件对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆