Does WPF have a native file dialog?

前端 未结 4 618
迷失自我
迷失自我 2020-12-23 16:09

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 refe

4条回答
  •  失恋的感觉
    2020-12-23 16:57

    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.

    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.

提交回复
热议问题