WPF子窗体实现单例模式

#1.子窗体类的代码:

  public partial class FormCommuConfig : Window
    {
        private static FormCommuConfig _FrmCommuConfig;
        public static FormCommuConfig Instance
        {
           get
            {
               if (_FrmCommuConfig == null)
                {
                    _FrmCommuConfig = new FormCommuConfig();
                }
                return _FrmCommuConfig;
            }
        }
        public FormCommuConfig()
        {
            InitializeComponent();
        }
        private void Window_Closed(object sender, EventArgs e)
        {
            _FrmCommuConfig = null;
        }
    }
}

#2.调用窗体:

 FormCommuConfig.Instance.ShowDialog();

你可能感兴趣的:(WPF学习,wpf,单例模式,c#)