C# WPF child window (about window)

2019-06-22 13:56发布

问题:

I have an application on C#/WPF that I`m developing ... I have a btn named About which should open a new window that contains details about the application or whatever I will put in it.

When I click the btn, a new window (about) opens, when I click again, while the new window (about) is opened another one is opened, how can I prevent this from happening, I also want the application to be disabled when the About window is opened and to be enabled when the About window is closed, Like most of the applications when about is clicked.

回答1:

You should use the ShowDialog Method: http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx

Code Sample:

// Instantiate window
AboutWindow aboutWindow = new AboutWindow();

// Show window modally
// NOTE: Returns only when window is closed
Nullable<bool> dialogResult = aboutWindow.ShowDialog();


回答2:

Just use ShowDialog() method instead of Show()

AboutWindow aboutWindow = new AboutWindow();
aboutWindow.ShowDialog();