Пример #1
0
        private void OnModuleActivated(ModuleEventArgs e)
        {
            var handler = this.ModuleActivated;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #2
0
 private void OnModuleTemplateCreated(ModuleEventArgs e)
 {
     var handler = this.ModuleTemplateCreated;
     if (handler != null) handler(this, e);
 }
Пример #3
0
        /// <summary>
        /// 构造模块的窗口
        /// </summary>
        /// <param name="moduleMeta"></param>
        public WorkspaceWindow CreateModule(WPFModuleMeta moduleMeta)
        {
            if (moduleMeta == null)
            {
                throw new ArgumentNullException("moduleMeta");
            }

            //创建 WorkspaceWindow
            var window = new ModuleWorkspaceWindow
            {
                ModuleMeta = moduleMeta,
                Title      = moduleMeta.Label
            };

            var args = new ModuleEventArgs(window);

            if (!moduleMeta.IsCustomUI)
            {
                try
                {
                    AutoUI.AggtUIFactory.PermissionModule = moduleMeta;

                    ControlResult ui = null;
                    //在 WPF 中,TemplateType 属性应该是继承自 UITemplate 的类,表示使用的自定义实体模块类型
                    if (moduleMeta.BlocksTemplate != null)
                    {
                        var module = Activator.CreateInstance(moduleMeta.BlocksTemplate) as UITemplate;
                        if (module == null)
                        {
                            throw new InvalidProgramException("WPF 中模板类需要从 UITemplate 类继承。");
                        }
                        window.Template            = module;
                        window.Template.EntityType = moduleMeta.EntityType;
                        this.OnModuleTemplateCreated(args);

                        window.Blocks = module.GetBlocks();
                        this.OnModuleBlocksCreated(args);

                        ui = module.CreateUI(window.Blocks);
                    }
                    else
                    {
                        AggtBlocks blocks = UIModel.AggtBlocks.GetModuleBlocks(moduleMeta);
                        window.Blocks = blocks;

                        this.OnModuleBlocksCreated(args);
                        ui = AutoUI.AggtUIFactory.GenerateControl(blocks);
                    }
                    window.WindowControl = ui.Control;
                    window.MainView      = ui.MainView;

                    Focus(ui);

                    //刚创建的窗体,尝试加载数据。
                    if (moduleMeta.TryAutoLoadData)
                    {
                        this.AsyncLoadListData(ui);
                    }
                }
                finally
                {
                    AutoUI.AggtUIFactory.PermissionModule = null;
                }
            }
            else
            {
                window.WindowControl = Activator.CreateInstance(moduleMeta.CustomUI) as FrameworkElement;
                if (window.WindowControl == null)
                {
                    throw new InvalidProgramException(moduleMeta.CustomUI + " 类型必须是一个 FrameworkElement。");
                }
            }

            AutomationProperties.SetName(window.WindowControl, moduleMeta.Label);

            this.OnModuleCreated(args);

            return(window);
        }
Пример #4
0
        /// <summary>
        /// 构造模块的窗口
        /// </summary>
        /// <param name="moduleMeta"></param>
        public WorkspaceWindow CreateModule(WPFModuleMeta moduleMeta)
        {
            if (moduleMeta == null) throw new ArgumentNullException("moduleMeta");

            //创建 WorkspaceWindow
            var window = new ModuleWorkspaceWindow
            {
                ModuleMeta = moduleMeta,
                Title = moduleMeta.Label
            };

            var args = new ModuleEventArgs(window);

            if (!moduleMeta.IsCustomUI)
            {
                try
                {
                    AutoUI.AggtUIFactory.PermissionModule = moduleMeta;

                    ControlResult ui = null;
                    //在 WPF 中,TemplateType 属性应该是继承自 UITemplate 的类,表示使用的自定义实体模块类型
                    if (moduleMeta.BlocksTemplate != null)
                    {
                        var module = Activator.CreateInstance(moduleMeta.BlocksTemplate) as UITemplate;
                        if (module == null) throw new InvalidProgramException("WPF 中模板类需要从 UITemplate 类继承。");
                        window.Template = module;
                        window.Template.EntityType = moduleMeta.EntityType;
                        this.OnModuleTemplateCreated(args);

                        window.Blocks = module.GetBlocks();
                        this.OnModuleBlocksCreated(args);

                        ui = module.CreateUI(window.Blocks);
                    }
                    else
                    {
                        AggtBlocks blocks = UIModel.AggtBlocks.GetModuleBlocks(moduleMeta);
                        window.Blocks = blocks;

                        this.OnModuleBlocksCreated(args);
                        ui = AutoUI.AggtUIFactory.GenerateControl(blocks);
                    }
                    window.WindowControl = ui.Control;
                    window.MainView = ui.MainView;

                    Focus(ui);

                    //刚创建的窗体,尝试加载数据。
                    if (moduleMeta.TryAutoLoadData) { this.AsyncLoadListData(ui); }
                }
                finally
                {
                    AutoUI.AggtUIFactory.PermissionModule = null;
                }
            }
            else
            {
                window.WindowControl = Activator.CreateInstance(moduleMeta.CustomUI) as FrameworkElement;
                if (window.WindowControl == null) throw new InvalidProgramException(moduleMeta.CustomUI + " 类型必须是一个 FrameworkElement。");
            }

            AutomationProperties.SetName(window.WindowControl, moduleMeta.Label);

            this.OnModuleCreated(args);

            return window;
        }