SaveFileDialog bug in WPF
Asked Answered
D

2

2

I'm using Microsoft.Win32.SaveFileDialog class to save my files. When I saved file, and minimize my app, I can't restore it back. It happens only after when used Microsoft.Win32.SaveFileDialog. Here is code:

Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = String.Format("{0} {1} {2}", ev["b"], ev["a"], ev["c"]);
dlg.DefaultExt = ".csv";
dlg.Filter = "Supported format (.csv)|*.csv";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
    string s = dlg.FileName;
    //other code
}

File saves successfully, but I don't know how to solve problem with minimizing. Does anybody knows what it could be?

Deprecative answered 26/3, 2012 at 15:32 Comment(3)
What is behind //other code?Innervate
Maybe wire up to the FileOK event and see you can catch an error there. Just a reach.Constantinople
@aleksey.berezan Writing string to file.Deprecative
C
3

WPF has all kinds of weird modality issues when you show dialogs without parent windows. I haven't seen this directly with the SaveFileDialog, but I have seen similar behavior with other dialogs. Try using the overload of .ShowDialog() where you pass in the parent window.

Chefoo answered 26/3, 2012 at 16:14 Comment(1)
Try using the overload of .ShowDialog() where you pass in the parent window., could be, I had same issue and solution in WinFormsInnervate
P
1

I encountered also a strange modality problem with WPF and the Win32 SaveFileDialog / OpenFileDialog.

What happens:

  • The modal state is violated / gets lost completely and the main window can be clicked while the OpenFileDialog is opened with ShowDialog()

When does it happen:

  • There was a task running before the OpenFileDialog opens
  • The debugger breaks into a breakpoint before running the task

Just create a simple WPF Application with a button click event:

    private void Button_Click(object sender, RoutedEventArgs e)
    { // <-- Breakpoint sits here

        Task.Run(() => {}).Wait();

        new Microsoft.Win32.OpenFileDialog().ShowDialog();
    }

Using the overloaded ShowDialog(Window owner) function solves this problem.

Pasta answered 8/6, 2015 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.