4

Run mspaint.exe and press Ctrl+O. The file extension filter shown has this special entry "All Picture Files". Now, how do I create such a filter in WPF? (I'm quite sure I've managed to do this in Win32 back in the days.)

Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".tif";
dlg.Filter =
    "All Picture Files|*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.jfif;*.tif;*.tiff;*.png|" +
    "All Files|*.*";

Nullable<bool> result = dlg.ShowDialog();

The code above works, but it yields these bloated filter labels:

All Picture Files (*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.jfif;*.tif;*.tiff;*.png)

All Files (*.*)

I didn't ask for those parentheses, so where do they come from?!

EDIT

Apparently, depending on the Windows option to hide the extension on known file types (in the Windows Explorer folder settings), the extensions are automatically added or not. I believe WPF does the right thing here!

l33t
  • 18,692
  • 16
  • 103
  • 180

0 Answers0