简体   繁体   中英

How to disable a wpf window?

I dont know if this is possible but, I call the following method to show a window in wpf:

Window window = Window.Show();

After the window has already loaded, I want to disable the window ie I dont want the user to be able to close the window until some condition is met...is this possible?

I tried:

window.IsEnabled = false , This works but the user can still close the Window...

Handle the Closing event and cancel if the condition is not met :

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
       if (/*condition not true*/)
        e.Cancel = true;
    }        

However, the user could find other means to close the window, a shutdown maybe? :)

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