如何搭建新的WPF项目框架

2019-12-26 13:02:37丽君
  •   if (constructors == null) //如果构造参数为null 
  • {  key = controlType.FullName; //key = T 的完全限定名 
  • }  else 
  • {  // 如果不为空 并且 第二个构造参数为string(第二个参数代表id -->有可能是GroupId 有可能是UserId); 
  • if (constructors.Length == 2 && constructors[1] is string) //ps:这里本人写死了可以根据需求自行修改  { 
  • key = controlType.FullName + constructors[1].ToString(); //key = 控件 完全限定名+id;  } 
  • else //不满足条件  { 
  • key = controlType.FullName; //key = 限定名  } 
  •   } 
  •   if (windowManager.ContainsKey(key)) //如果包含KEY 
  • {  windowManager[key].Topmost = true; //设置TopMost 
  • return;  } 
  •   UserControl content; 
  • if (constructors == null)  { 
  • content = Activator.CreateInstance(controlType) as UserControl;  } 
  • else  { 
  • content = Activator.CreateInstance(controlType, constructors) as UserControl;  } 
  •   BaseWindow window = new BaseWindow(); //PS这是自己封装 的Window,(可以用直接用原始的Wpf Widnow) 
  • window.Title = title;  windowManager.Add(key, window); 
  • window.Closed += (sen, cloE) =>  { 
  • windowManager.Remove(key);  }; 
  • if (isDialog)  { 
  • window.ShowDialog();  } 
  • else  { 
  • window.Show();  } 
  • #region 注册关闭事件  if (content.DataContext as CustomViewModel != null) 
  • {  CustomViewModel vm = content.DataContext as CustomViewModel; 
  • vm.CloseEvent += (obj) =>  { 
  • if (content.DataContext.Equals(obj))  { 
  • window.Close();  } 
  • };  }