//使用方法
this.ReflectionCallInterface("COSMO.IM.Client.Scan", "Scan_New_Skin", "上线扫描");
/// <summary>
/// 通过反射打开点击的界面
/// </summary>
/// <param name="projectName">dll名称,程序集名称</param>
/// <param name="className">类名</param>
/// <param name="formTitle">界面标题</param>
private void ReflectionCallInterface(string projectName, string className, string formTitle)
{
logger.Info("进入了ReflectionCallInterface方法");
try
{
logger.Info("要准备实例化窗体的UserControl的类名叫:" + projectName + "." + className);
// Assembly.Load("COSMO.IM.Client.Scan").CreateInstance("COSMO.IM.Client.Scan.Scan_New_Skin");
UserControl uc = (UserControl)Assembly.Load(projectName).CreateInstance(projectName + "." + className);
logger.Info("实例化了一个窗体的UserControl");
Type type = uc.GetType();
//string title = "", haierLogo = "", cosmoLogo = "";
#region 获取接口定义的公共属性
//if (type != null)
//{
// PropertyInfo piTitle = type.GetProperty("BaseTitle");
// if (piTitle != null)
// {
// title = piTitle.GetValue(uc, null).ToString();
// }
// PropertyInfo piHaierLogo = type.GetProperty("BaseHaierLogo");
// if (piHaierLogo != null)
// {
// haierLogo = piHaierLogo.GetValue(uc, null).ToString();
// }
// PropertyInfo piCosmoLogo = type.GetProperty("BaseCosmoLogo");
// if (piCosmoLogo != null)
// {
// cosmoLogo = piCosmoLogo.GetValue(uc, null).ToString();
// }
//}
logger.Info("准备设置窗体的Title");
if (!string.IsNullOrEmpty(formTitle))
{
//判断是否存在该键 如果不存在就用传入的数据当做标题
if (map_MenuItem.ContainsKey(formTitle))
{
if (string.IsNullOrEmpty(Global.GetAppSetting(map_MenuItem[formTitle])))
{
this.wlblTitle.Content = formTitle;
}
else
{
this.wlblTitle.Content = Global.GetAppSetting(map_MenuItem[formTitle]);
}
}
}
logger.Info("设置窗体的Title结束");
//if (!string.IsNullOrEmpty(haierLogo))
//{
// this.imgHaierLogo.Source = new BitmapImage(new Uri(haierLogo, UriKind.RelativeOrAbsolute));
//}
//if (!string.IsNullOrEmpty(cosmoLogo))
//{
// this.imgCosmoLogo.Source = new BitmapImage(new Uri(cosmoLogo, UriKind.RelativeOrAbsolute));
//}
#endregion 获取接口定义的公共属性
logger.Info("准备将用户控件加载到MainWindow的容器窗体");
this.ContentControl.Content = uc;//加载子窗口
logger.Info("将用户控件加载到MainWindow的容器窗体成功");
}
catch (Exception ex)
{
logger.Info("ReflectionCallInterface方法报错了,详细信息:\n" + ex.ToString());
MessageBox.Show(ex.Message);
}
}