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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
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 theOpenFileDialog
andSaveFileDialog
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.You can create a simple attached property to add this functionality to a TextBox. Open file dialog can be used like this:
The code for OpenFileDialogEx:
I used the solution presented by Gregor S. and it works well, although I had to convert it to a VB.NET solution, here is my conversion if it helps anyone...
Thanks to Gregor S for a neat solution.
In Visual Studio 2010 it seems to crash the designer however - so I've tweaked the code in the OpenFileDialogEx class. The XAML code stays the same: