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.