我有一个打开的窗口,我正在使用.Show()方法,我想阻止任何其他窗口打开如果我有一个打开的窗口。除了ShowDialog()之外的东西。
答案 0 :(得分:1)
在您以某种方式打开时,跟踪打开的窗口数量,例如:
public class WindowService
{
private const int MaxNumberOfOpenWindows = 1;
private int _currentNumberOfOpenWindows = 0;
public void OpenWindow()
{
if (_currentNumberOfOpenWindows != MaxNumberOfOpenWindows)
{
Window window = new Window();
window.Closed += Window_Closed;
window.Show();
_currentNumberOfOpenWindows++;
}
}
private void Window_Closed(object sender, EventArgs e)
{
Window window = (Window)sender;
window.Closed -= Window_Closed;
_currentNumberOfOpenWindows--;
}
}