Wpf 与TabItems相同的模块多次

Wpf 与TabItems相同的模块多次,wpf,prism,Wpf,Prism,以下是我的设想: 具有1个TabControl和1个称为MenuRegion的区域的Shell MenuRegion包含每个可用模块(应用程序)的按钮 我想使用Prism(WPF的复合应用程序库)实现以下功能:单击其中一个按钮时,我需要向TabControl添加一个新的TabItem,并在该TabItem中加载相应模块(应用程序)的单个实例。 一个模块可能会在选项卡控件中出现多次 我真的很感激你的回答。但我不相信你在用棱镜,是吗?我的问题与Prism更相关,现在我对它进行了编辑以使其更加清晰

以下是我的设想:

  • 具有1个TabControl和1个称为MenuRegion的区域的Shell
  • MenuRegion包含每个可用模块(应用程序)的按钮
  • 我想使用Prism(WPF的复合应用程序库)实现以下功能:单击其中一个按钮时,我需要向TabControl添加一个新的TabItem,并在该TabItem中加载相应模块(应用程序)的单个实例。 一个模块可能会在选项卡控件中出现多次


    我真的很感激你的回答。但我不相信你在用棱镜,是吗?我的问题与Prism更相关,现在我对它进行了编辑以使其更加清晰

    在Prism中,可以将模块的视图动态加载到区域中。我不确定在我的场景中如何做到这一点,因为区域是动态设置的。我怎么称呼他们


    谢谢

    我们做了类似的事情,尽管我们已经创建了选项卡项(没有内容)并根据需要显示/隐藏。选择选项卡项后,我们将加载选项卡内容

    private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.OriginalSource != sender) return;
    
            TabControl tabControl = (TabControl)sender;
            TabItem tabItem = (TabItem)tabControl.SelectedItem;
    
            if (!tabItem.HasContent)
                AddTabContent(tabItem); // This will cause a refresh once the content is loaded.
            else
                Refresh(tabItem);
        }
    
    
    
    private void AddTabContent(TabItem tabItem)
        {
            IOptimusPage page = tabItem.Tag as IOptimusPage;
    
            //This allows lazy loading of controls
            if (page != null)
            {
                if (!tabItem.HasContent)
                {
                    CustomerEngagementUserControl control = page.GetControl(DataContext as CustomerEngagementUIObject, Services);
    
                    tabItem.Content = control;
                }
            }
    
        }
    
    选项卡项内容在选项卡项标记中指定,使用负责创建内容的页面

    <TabItem
    Header="Personal Background"
    Style="{StaticResource FirstBreadcrumbTabItem}"
    x:Name="PersonalBackgroundTab">
        <TabItem.Tag>
            <Pages:FfnaPersonalBackgroundPage />
        </TabItem.Tag>
    </TabItem>
    

    您可以使用类似的技术动态创建选项卡项。

    我们也会做类似的事情,尽管我们已经创建了选项卡项(没有内容)并根据需要显示/隐藏。选择选项卡项后,我们将加载选项卡内容

    private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.OriginalSource != sender) return;
    
            TabControl tabControl = (TabControl)sender;
            TabItem tabItem = (TabItem)tabControl.SelectedItem;
    
            if (!tabItem.HasContent)
                AddTabContent(tabItem); // This will cause a refresh once the content is loaded.
            else
                Refresh(tabItem);
        }
    
    
    
    private void AddTabContent(TabItem tabItem)
        {
            IOptimusPage page = tabItem.Tag as IOptimusPage;
    
            //This allows lazy loading of controls
            if (page != null)
            {
                if (!tabItem.HasContent)
                {
                    CustomerEngagementUserControl control = page.GetControl(DataContext as CustomerEngagementUIObject, Services);
    
                    tabItem.Content = control;
                }
            }
    
        }
    
    选项卡项内容在选项卡项标记中指定,使用负责创建内容的页面

    <TabItem
    Header="Personal Background"
    Style="{StaticResource FirstBreadcrumbTabItem}"
    x:Name="PersonalBackgroundTab">
        <TabItem.Tag>
            <Pages:FfnaPersonalBackgroundPage />
        </TabItem.Tag>
    </TabItem>
    

    您可以使用类似的技术动态创建选项卡项。

    我知道响应时间已经很晚了,但我正在做类似的事情,尽管尚未实现完整的解决方案

    这段代码发生在我在presenter中处理的按钮的单击事件上。该模块在配置文件中定义

    ModuleInfo moduleInfoObject = this.moduleEnumerator.GetModule("ModuleA"); 
    
    Assembly assembly = this.LoadAssembly(moduleInfoObject);
    
    Type type = assembly.GetType(moduleInfoObject.ModuleType);
    IModule aModule = this.CreateModule(type);                                    
    aModule.Initialize();  
    
    
    // - - - -Helper Methods - - - -
    // - - - LoadAssembly - - -       
    private Assembly LoadAssembly(ModuleInfo moduleInfo)
        {            
            string assemblyFile = moduleInfo.AssemblyFile;
            assemblyFile = this.GetModulePath(assemblyFile);
    
            FileInfo file = new FileInfo(assemblyFile);
            Assembly assembly;
    
            try
            {
                assembly = Assembly.LoadFrom(file.FullName);
            } 
            catch (Exception ex)
            {
                throw new ModuleLoadException(null, assemblyFile, ex.Message, ex);
            } 
    
            return assembly;
    
        } // LoadAssembly(moduleInfo)
    
    
    // - - - CreateModule - - -
    private IModule CreateModule(Type type)
        {
            return (IModule)containerFacade.Resolve(type);            
        } // CreateModule(type)
    
    
    // - - - GetModulePath - - -
    private string GetModulePath(string assemblyFile)
        {
            if (String.IsNullOrEmpty(assemblyFile))
            {
                throw new ArgumentNullException("assemblyFile");
            } // if
    
            if (Path.IsPathRooted(assemblyFile) == false)
            {
                assemblyFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyFile);
            } // if
    
            return assemblyFile;
        } // GetModulePath(assemblyFile)
    

    我知道现在回复已经很晚了,但我也在做类似的事情,虽然还没有完全解决问题

    这段代码发生在我在presenter中处理的按钮的单击事件上。该模块在配置文件中定义

    ModuleInfo moduleInfoObject = this.moduleEnumerator.GetModule("ModuleA"); 
    
    Assembly assembly = this.LoadAssembly(moduleInfoObject);
    
    Type type = assembly.GetType(moduleInfoObject.ModuleType);
    IModule aModule = this.CreateModule(type);                                    
    aModule.Initialize();  
    
    
    // - - - -Helper Methods - - - -
    // - - - LoadAssembly - - -       
    private Assembly LoadAssembly(ModuleInfo moduleInfo)
        {            
            string assemblyFile = moduleInfo.AssemblyFile;
            assemblyFile = this.GetModulePath(assemblyFile);
    
            FileInfo file = new FileInfo(assemblyFile);
            Assembly assembly;
    
            try
            {
                assembly = Assembly.LoadFrom(file.FullName);
            } 
            catch (Exception ex)
            {
                throw new ModuleLoadException(null, assemblyFile, ex.Message, ex);
            } 
    
            return assembly;
    
        } // LoadAssembly(moduleInfo)
    
    
    // - - - CreateModule - - -
    private IModule CreateModule(Type type)
        {
            return (IModule)containerFacade.Resolve(type);            
        } // CreateModule(type)
    
    
    // - - - GetModulePath - - -
    private string GetModulePath(string assemblyFile)
        {
            if (String.IsNullOrEmpty(assemblyFile))
            {
                throw new ArgumentNullException("assemblyFile");
            } // if
    
            if (Path.IsPathRooted(assemblyFile) == false)
            {
                assemblyFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyFile);
            } // if
    
            return assemblyFile;
        } // GetModulePath(assemblyFile)
    

    我是这个棱镜世界的新手(1周的经验:)),有同样的要求! 首先,你必须从那里得到Regionextensions

    我(可能是你)的问题的解决方案如下:

    • 有2个区域(菜单和选项卡控件-用于类似mdi的行为)

    • tabitem头必须准备一个用于关闭的按钮(该按钮绑定到用于关闭此tabitem的命令,实际上隐藏了此tabitem)

    • 将事件从菜单项发送到应该加载视图的模块(我已经按需实例化了模块)。在模块的初始化方法中,订阅菜单项发送的事件。在事件处理方法中,只需重新显示tabitem


    如果这是为了向您抽象,我可以向您发送一个我开发的框架应用程序。

    我是这个PRISM世界的新手(1周经验:)),并且有相同的要求! 首先,你必须从那里得到Regionextensions

    我(可能是你)的问题的解决方案如下:

    • 有2个区域(菜单和选项卡控件-用于类似mdi的行为)

    • tabitem头必须准备一个用于关闭的按钮(该按钮绑定到用于关闭此tabitem的命令,实际上隐藏了此tabitem)

    • 将事件从菜单项发送到应该加载视图的模块(我已经按需实例化了模块)。在模块的初始化方法中,订阅菜单项发送的事件。在事件处理方法中,只需重新显示tabitem

    如果这是抽象给你,我可以给你一个框架应用程序,我已经开发出来玩