This project has moved. For the latest updates, please go here.

Cannot set Visibility or call Show or ShowDialog after window has closed

Jul 20, 2010 at 8:10 AM
Edited Jul 21, 2010 at 6:53 AM

Plz help me this error : "Cannot set Visibility or call Show or ShowDialog after window has closed" 

I'm trying open and close Modalless dialog.



Jul 23, 2010 at 6:23 PM

This is a limitation of WPF. A Window cannot be reused after it was closed. But you can create a new object of your modal Window and show it.

How this can be done is shown in the ViewModel (EmailClient) sample application. Please open the ‘EmailClient.Presentation’ project and have a look into the ‘Views\EmailAccountsWizard\EmailAccountsWizard.xaml.cs’ file. It uses additionally the PartCreationPolicy attribute to tell MEF that this View should not be shared (not be used as a singleton). The same is done in the EmailAccountsViewModel class. This way we get new instances every time the Controller calls:

emailAccountsViewModel = container.GetExportedValue<EmailAccountsViewModel>();

Best Regards,

Jul 26, 2010 at 2:18 AM

Thanks for reply,

In the ViewModel (EmailClient)  sample application, you used ShowDialog is Modal dialog, but my sample want to using modaless dialog, that mean i can manipulate other application of window, I want to show capture form contains some function : capture area, capture fullscreen...

I has resolved show dialog as you show me, but i have a problem: when I close the application, it seems that it is still running, if I run in debug mode when I close the application, the debugging process is still running and I have to turn off (manual) by pressing the "stop" button in the Visual Studio. I thought, maybe the cause is my Capture  Form is modaless using a control window.

Thank you again, please give me solution or your opinions.

Jul 28, 2010 at 6:16 PM

Have you set the Owner property of the modaless dialogs?

public void Show(object owner)
    Owner = owner as Window;
    Show ();

I believe this should solve your issue.

Aug 10, 2010 at 4:02 AM

ok, thanks.