WPF ShowDialog returns immediately
- by dthrasher
Sometimes when I call ShowDialog on an OpenFileDialog Window in WPF, the dialog closes immediately with a return value of false.
I'm calling ShowDialog in response to a button click event. I can reproduce this problem using the sample code for OpenFileDialog on MSDN:
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;
}
The problem occurs intermittently when I run my solution in Debug mode from Visual Studio 2008 SP1. It's quite annoying.
Is this a known issue? Are there workarounds?