-1

I have a dialog that works just fine the first time it is invoked. However the second time I get

System.InvalidOperationException: 'Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.'

To save construction I am using the same Window for every dialog call. It looks like

    var result = PreferencesView.ShowDialog();

I could over come this by doing something like

var result = new PreferencesView().ShowDialog();

But I would like to use just one Window. Also although I have simplified it here, in real-life constructing the view involves resolving many dependencies (logging, localization, preferences, etc.). I have read solutions here. But adding OnClosing prevents the error but seems to keep the window visible after the second time.

Kevin Burton
  • 2,032
  • 4
  • 26
  • 43
  • Have you tried using show and setting the owner of the window and then calling Hide when closing window? – XAMlMAX Apr 24 '21 at 21:01

1 Answers1

-1

i haven't tried it but, it should be possible if you use Form.Hide() instead of Form.Close().

Greetings,

AW