C#WPF子窗口(关于窗口)

时间:2021-04-17 07:30:11

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.

我在C#/ WPF上有一个我正在开发的应用程序......我有一个名为About的btn,它应该打开一个新窗口,其中包含有关应用程序的详细信息或我将放入其中的任何内容。

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.

当我单击btn时,会打开一个新窗口(about),当我再次单击时,在打开新窗口(about)时会打开另一个窗口,如何防止这种情况发生,我还希望在禁用时关闭应用程序关闭窗口打开并在关闭窗口关闭时启用,与单击关于时的大多数应用程序一样。

2 个解决方案

#1


5  

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

您应该使用ShowDialog方法: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


1  

Just use ShowDialog() method instead of Show()

只需使用ShowDialog()方法而不是Show()

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

#1


5  

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

您应该使用ShowDialog方法: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


1  

Just use ShowDialog() method instead of Show()

只需使用ShowDialog()方法而不是Show()

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