コード例 #1
0
 private void MenuDoubleClick(lgsv.MenuItem mi)
 {
     if (null == mi)
     {
         return;
     }
     if (null != mi.InvokingConfig && "" != mi.InvokingConfig)
     {
         ShowWindow(mi);
     }
 }
コード例 #2
0
        private void ShowWindow(lgsv.MenuItem mi)
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml(mi.InvokingConfig);
            XmlNodeList xlist   = xdoc.GetElementsByTagName("DSPUSERCONTROL");
            string      dllPath = "";
            string      dllName = "";

            try
            {
                //if (!IsOpenTab(xlist.Item(0).ChildNodes[1].InnerText))
                {
                    dllPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                    dllName = xlist.Item(0).ChildNodes[0].InnerText;
                    dllPath = System.IO.Path.Combine(dllPath, dllName + ".dll");
                    Assembly ass = Assembly.LoadFrom(dllPath);
                    Type     t   = ass.GetType(xlist.Item(0).ChildNodes[1].InnerText);

                    foreach (MetroTabItem obj in this.tblMainRegion.Items)
                    {
                        if (obj.Content != null && obj.Content.GetType() == t)
                        {
                            obj.IsSelected = true;
                            return;
                        }
                    }
                    ConstructorInfo constructors = null;
                    Type[]          ts           = null;
                    object[]        parms        = null;
                    if (xlist.Item(0).ChildNodes[2].InnerText == "")
                    {
                        ts    = new Type[] { };
                        parms = new object[] { };
                    }
                    else
                    {
                        string[] parmlist = xlist.Item(0).ChildNodes[2].InnerText.Split(new char[] { ',' });
                        ts    = new Type[parmlist.Length];
                        parms = new object[parmlist.Length];
                        for (int i = 0; i < parmlist.Length; i++)
                        {
                            ts[i]    = Type.GetType(parmlist[i].Split(new char[] { ':' })[1]);
                            parms[i] = Convert.ChangeType(parmlist[i].Split(new char[] { ':' })[2], ts[i]);
                        }
                    }
                    constructors = t.GetConstructor(ts);
                    MetroContentControl f = constructors.Invoke(parms) as MetroContentControl;
                    if (f != null)
                    {
                        MetroTabItem tabitem = new MetroTabItem();
                        tabitem.Header  = mi.Name;
                        tabitem.Content = f;

                        tabitem.CloseTabCommand = CloseTabCommand;

                        if (!this.tblMainRegion.Items.Contains(tabitem))
                        {
                            this.tblMainRegion.Items.Add(tabitem);
                        }
                        tabitem.IsSelected = true;
                    }
                }
            }
            catch (FileNotFoundException fe)
            {
                MessageBox.Show("未找到" + dllPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }