You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Core.CodeBinding.Common
{
/// <summary>
/// 窗口管理器
/// </summary>
public class WindowManager
{
static Dictionary<string, WindowStruct> _regWindowContainer = new Dictionary<string, WindowStruct>();
/// <summary>
/// 注册类型
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="name"></param>
/// <param name="owner"></param>
public static void Register<T>(string name, System.Windows.Window owner = null)
{
if (!_regWindowContainer.ContainsKey(name))
{
_regWindowContainer.Add(name, new WindowStruct { WindowType = typeof(T), Owner = owner });
}
}
/// <summary>
/// 获取对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="name"></param>
/// <param name="dataContext"></param>
/// <returns></returns>
public static bool ShowDialog<T>(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; }
}
}