Bab*_*bad 4 c# wpf xaml window
我正在使用WPF(C#)编写程序.我使用这样的方法来打开和关闭窗口:
public static void openCloseWindow(Window toBeOpen, Window toBeClose)
{
toBeOpen.Show();
makeWindowCenter(toBeOpen);
toBeClose.Close();
}
Run Code Online (Sandbox Code Playgroud)
在程序的一部分我使用这样的方法:
openCloseWindow(new BestCustomerWindow,this);
Run Code Online (Sandbox Code Playgroud)
因此,最终用户可以在按钮上多次单击,并且可以打开许多窗口.
有没有办法避免在运行时打开窗户?
欲获得更多信息:
让我点击一个打开window1的按钮.我想要:
Rhy*_*wey 12
替换WINDOWNAME为所需窗口的名称:
bool isWindowOpen = false;
foreach (Window w in Application.Current.Windows)
{
if (w is WINDOWNAME)
{
isWindowOpen = true;
w.Activate();
}
}
if (!isWindowOpen)
{
WINDOWNAME newwindow = new WINDOWNAME();
newwindow.Show();
}
Run Code Online (Sandbox Code Playgroud)