using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Admin.Core.Wpf.Common { /// /// 窗口管理器 /// public class WindowManager { static Dictionary _regWindowContainer = new Dictionary(); /// /// 注册类型 /// /// /// /// public static void Register(string name, System.Windows.Window owner = null) { if (!_regWindowContainer.ContainsKey(name)) { _regWindowContainer.Add(name, new WindowStruct { WindowType = typeof(T), Owner = owner }); } } /// /// 获取对象 /// /// /// /// /// public static bool ShowDialog(string name, T dataContext) { if (_regWindowContainer.ContainsKey(name)) { Type type = _regWindowContainer[name].WindowType; //反射创建窗体对象 var window = (System.Windows.Window)Activator.CreateInstance(type); window.Owner = _regWindowContainer[name].Owner; window.DataContext = dataContext; return window.ShowDialog() == true; } return false; } } public class WindowStruct { public Type WindowType { get; set; } public System.Windows.Window Owner { get; set; } } }