M.kazem Akhgary
M.kazem Akhgary

Reputation: 19149

Open file Dialog Filter Hides Everything WPF

I have OpenFileDialog. when i set Filter to opd to only show files with 'x' extension it will hide every thing.

im new to WPF. i didnt put opd Control (like in WinForm) inside WPF because i couldnt find it.

OpenFileDialog works fine when i set filter to * . * to show all files.

i Checked the extension of files and it was correct.

also i searched in for this problem and didnt find anything.

thanks for help.

        OpenFileDialog opd = new OpenFileDialog
        {
            FileName = "X File",
            DefaultExt = ".x",
            Filter = "X Files (*.x)|*.x | All Files (*.*)|*.*",
            Multiselect = true
        };

        bool? result = opd.ShowDialog();

        if (result == true)
        {
            //...
        }

Upvotes: 0

Views: 853

Answers (2)

Geno Carman
Geno Carman

Reputation: 11

I was using "game config files|*.cfg|All files| *. "

Selecting star.star hid all files instead of showing them. Fixed it by removing the TRAILING SPACE from the filter string.

Upvotes: 0

Sébastien Sevrin
Sébastien Sevrin

Reputation: 5405

You should change your filter from

"X Files (*.x)|*.x | All Files (*.*)|*.*"

To

"X Files (*.x)|*.x|All Files (*.*)|*.*"

As stated in MSDN:

Do not put spaces before or after the vertical bars in the filter string. This will cause incorrect behavior in the filter.

Upvotes: 5

Related Questions