我的自定义弹出窗口应该是单身吗?

时间:2013-06-20 15:18:22

标签: c# winforms singleton

我的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;
            }
        }
    }

0 个答案:

没有答案
相关问题