通过类库加载用户自定义控件到定制子窗口

4 篇文章 0 订阅
//使用方法  
 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);
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bingo_BIG

你的鼓励是我最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值