WPF ShowDialog again/several times

wpf dialog
wpf close window on button click
wpf cancel window closing
wpf window closing event

i´ve got an WPF application with an "settings-winwow". if i´m clicking on "info" on the mainwindow, settings.showDialog(); is called - so far so good. It opens and i can do some stuff, bus when i´m closing it and try to open it again, it gives me an error. its called:

System.InvalidOperationException

HResult=0x80131509

message = Visibility cant be shown or defined, ShowDialog or WindowInteropHelper.EnsureHandle cant be called, after the window was closed.

i found this:

    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
        this.Visibility = Visibility.Hidden;
    }

here on SO, but i doesn´t work or maybe i´m using it the wrong way.. Can anybody help me?


If you want to reuse the window you should consider to use Show instead of ShowDialog. ShowDialog will destroy the object when you close the window. Using `Show' won't block the calling main window. This may be undesirable in your case.

The codes snipped you posted will prevent the destruction of your object by hiding the window instead of closing it. If you want to use you snipped, the copy it to your window.

Your XAML code:

Window x:Class="WpfTestApp.DialogWindow"
    ...
    Closing="Window_Closing">

The C# code in code behind:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
    this.Visibility = Visibility.Hidden;
}

or use Show instead like this:

DialogWindow.Show();

WPF ShowDialog again/several times, WPF ShowDialog again/several times. wpf dialog wpf window closed event wpf usercontrol closing event wpf window closing event not firing wpf close window  When a modal WPF window (a window opened by calling ShowDialog) is closed, the previously activated window is reactivated. If a modal WPF window has an owner window (see Owner), the owner window is not reactivated when the modal WPF window is closed unless it was the previously activated window.


You can only call ShowDialog once on the window. For the next call you need to create a new window.

So the code when clicking on the 'info ' should be:

settings = new SettingsWindow();
settings.ShowDialog();

WPFWindow ShowDialog not working the second time? in UI for , If it does, then allGood stays false and the loop happens again. you please give us some more information - what version of RadControls for WPF do you use​,  Clicking the button multiple times keeps increasing the number of dialogs open (ShowDialog () calls). Commenting out the indicated line in MainWindow.xaml.cs works around the bug.


You can call several times Window.ShowDialog()

But you should never call Close() method (until you don't want to use the control anymore: Close is like Dispose for controls).

Instead you can use Hide().

Then the next call to ShowDialog() should work as a Show() call.

When the dialog is hidden, other windows and other dialogs should continue to work as usual.

Transform Close() calls to Hide()

protected override void OnClosing(CancelEventArgs e)
{
    e.Cancel = true;
    Hide();
}

WPF ShowDialog() never returns when a dialog's owner is closed , Clicking the button multiple times keeps increasing the number of dialogs open (​ShowDialog() calls). Commenting out the indicated line in  Recommend:c# - Win32Exception occurs when ShowDialog for a WPF window (w/ ribbon buttons) showing up in Excel. When I click one ribbon button, a WPF window will pop up. It works fine for a while. However, after I click ribbon buttons several times and click one button again, nothing shows up. I checked my log. c# wpf showdialog |


Visual Basic 2008 Programmer's Reference, That page has a button that navigates back to the first page. If the user moves back and forth several times, the browser's history will be cluttered with entries such as: Page 1, Page 2, Page 1, Page 2, Page 2, and so forth. In a WPF application, you create Window objects and use their Show or ShowDialog methods. Join a community of over 2.6m developers to have your questions answered on WPFWindow ShowDialog not working the second time? of UI for WPF Window. New here? Start with our free trials.


WPF Window Closing Errors, For quite a while in Markdown Monster I've had a number of errors showing up in my Cannot set Visibility to Visible or call Show, ShowDialog, Close, Cancel = true; // this allows closing again IsClosing = false; return; } }. There are only two ways to display a form in .NET: Show and ShowDialog. If you have multiple copies appearing then it is not the use of either that is the problem - it is that you are constructing new instances instead of using the same instance each time.


https://social.msdn.microsoft.com/Forums/vstudio/e, Visibility is set, or Show(), ShowDialog(), or Close() is called while a window DataWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation​" If you want to show and hide a window multiple times during the lifetime of an​  While neither of the articles were using WPF, extensive testing showed that using ApplicationContexts and Application.Run instead of ShowDialog() made WPF (and WinForms) work far better. The NotifyIcon issue took a number of days to resolve as I battled with unresponsiveness when clicking on the ContextMenu to Exit.