简体   繁体   中英

How to create a modal window?

I am new to C# and WPF. I want to open a new window and remain totally in that window locking the parent ie something similar to MessageBox

I have a menu item that I choose calls a method OnClose, I then create and show my confirm close window. I disable the parent but it runs through the entire method I want to wait until the second windows I created has closed.

    void OnClose(object sender, ExecutedRoutedEventArgs args)
    {
        //this.IsEnabled = true;
        ConfirmClose cc = new ConfirmClose();
        this.IsEnabled = false;
        cc.Show();
        cc.Focus();
 // How can I wait here until the windows cc has closed
        this.IsEnabled = true;


    }

Instead of .Show() use .ShowDialog() , then the user can't return to the parent window unless he close the form, like this:

 ConfirmClose cc = new ConfirmClose();
 cc.ShowDialog();

Assuming that ConfirmClose is a System.Windows .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM