Esempio n. 1
0
        public MDIWPF()
        {
            InitializeComponent();
            foreach (Type i in AppDomain.CurrentDomain.ScanType(value => value.GetCustomAttribute <AutoLoadTemplate>() != null, value => true))
            {
                AutoLoadTemplate template = i.GetCustomAttribute <AutoLoadTemplate>();
                if (!MenuList.ContainsKey(template.Catalog))
                {
                    MenuList[template.Catalog] = new MenuItem()
                    {
                        Header = template.Catalog.EnumGetFieldAttribute <DescriptionAttribute>()?.Description ?? template.Catalog.ToString(),
                    }
                }
                ;
                MenuItem item = new MenuItem
                {
                    Header = template.TabName
                };
                item.Click += Item_Click;;
                MenuList[template.Catalog].Items.Add(item);
                FormType[item] = i;
            }

            foreach (MenuItem i in MenuList.Values)
            {
                main_menu.Items.Add(i);
            }
        }

        WindowInteropHelper selfInterop => new WindowInteropHelper(this);
Esempio n. 2
0
        private void Item_Click(object sender, RoutedEventArgs e)
        {
            Type             type     = FormType[sender as MenuItem];
            AutoLoadTemplate template = type.GetCustomAttribute <AutoLoadTemplate>();
            Window           window   = new Window
            {
                Content = Activator.CreateInstance(type) as Control,
                Title   = template.TabName,
                Width   = Width,
                Height  = Height,
                WindowStartupLocation = WindowStartupLocation.CenterOwner
            };

            window.Show();
            SetParent(new WindowInteropHelper(window).Handle, selfInterop.Handle);
        }
Esempio n. 3
0
        private void Menu_Click(object sender, EventArgs e)
        {
            Type             type     = FormCollection[sender as ToolStripMenuItem];
            AutoLoadTemplate template = type.GetCustomAttribute <AutoLoadTemplate>();
            Form             window   = new Form
            {
                Text        = template.TabName,
                MdiParent   = this,
                WindowState = FormWindowState.Maximized
            };

            System.Windows.Controls.UserControl ctl = Activator.CreateInstance(type) as System.Windows.Controls.UserControl;
            ctl.Margin = new System.Windows.Thickness(0, 0, 0, 0);
            window.Controls.Add(new ElementHost
            {
                Child = ctl,
                Dock  = DockStyle.Fill,
            });
            window.Show();
        }
Esempio n. 4
0
 private void MDIParent1_Load(object sender, EventArgs e)
 {
     foreach (Type i in AppDomain.CurrentDomain.ScanType(value => value.GetCustomAttribute <AutoLoadTemplate>() != null, value => true))
     {
         AutoLoadTemplate template = i.GetCustomAttribute <AutoLoadTemplate>();
         if (!Catelog.ContainsKey(template.Catalog))
         {
             ToolStripMenuItem item = new ToolStripMenuItem
             {
                 Text = template.Catalog.EnumGetFieldAttribute <DescriptionAttribute>()?.Description ?? template.Catalog.ToString(),
             };
             Catelog[template.Catalog] = item;
             menuStrip.Items.Add(item);
         }
         ToolStripMenuItem menu = new ToolStripMenuItem()
         {
             Text = template.TabName
         };
         Catelog[template.Catalog].DropDownItems.Add(menu);
         FormCollection[menu] = i;
         menu.Click          += Menu_Click;
     }
 }