我的 DLL 中有 3-4 个其他 DLL 使用的弹出自定义窗口。这些窗口以模态方式弹出。
我的自定义窗口应该是单例吗?
是否应该这样调用:
NeXusCustomWindowDlg.Instance.CustomWndDlg.Show("Recipe properties", ctl, 600, 600);
...
NeXusCustomWindowDlg.Instance.Close()
相关代码:
public void Show(string title, object content, double width, double height)
{
Window newWindow = new Window
{
BorderBrush = Brushes.Blue,
BorderThickness = new Thickness(3),
Title = title,
Content = content,
WindowStyle = System.Windows.WindowStyle.ToolWindow,
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen,
ResizeMode = System.Windows.ResizeMode.NoResize,
Width = width,
Height = height,
VerticalContentAlignment = VerticalAlignment.Stretch
};
//WindowStyle = System.Windows.WindowStyle.None,
OpenedWindow = newWindow;
newWindow.ShowDialog();
newWindow.Content = null;
}
public void Close()
{
if (OpenedWindow != null)
{
OpenedWindow.Close();
}
}
private Window OpenedWindow
{
get
{
lock (_syncObj)
{
return _openedWindow;
}
}
set
{
lock (_syncObj)
{
_openedWindow = value;
}
}
}