1

这是我的场景:

  1. 带有 1 个 TabControl 和 1 个名为 MenuRegion 的区域的外壳
  2. MenuRegion 包含每个可用模块(应用程序)的按钮。

我想使用 Prism (Composite Application Library for WPF) 实现以下目标:单击其中一个按钮时,我需要向 TabControl 添加一个新的 TabItem,并在此 TabItem 内加载相应模块(应用程序)的单个实例. 一个模块可能会在 TabControl 中出现多次。


我真的很感谢你的回答。但我不相信您使用的是 Prism ( http://www.codeplex.com/CompositeWPF ) 是吗?我的问题与棱镜更相关,我现在对其进行了编辑以使其更加清晰。

在 Prism 中,您可以将模块的视图动态加载到区域中。我不确定如何在我的场景中做到这一点,因为这些区域是动态设置的。我将如何命名它们?

谢谢!

4

3 回答 3

1

我是这个 PRISM 世界的新手(1 周经验 :)))并且有同样的要求!首先,您必须从此处获取 Regionextensions 。

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

  • 有 2 个区域(菜单和 tabcontrol - 用于类似 mdi 的行为)

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

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

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

于 2009-10-08T19:52:10.580 回答
0

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

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>

页面创建控件。

class FfnaPersonalBackgroundPage : IOptimusPage
{
    #region IOptimusPage Members

    public CustomerEngagementUserControl GetControl(CustomerEngagementUIObject dataContext, CustomerEngagementServices services)
    {
        CustomerEngagementUserControl control = new FfnaPersonalBackgroundControl();
        control.DataContext = dataContext;
        control.Services = services;
        return control;
    }

    #endregion
}

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

于 2009-01-16T20:53:16.553 回答
0

我知道响应已经很晚了,但我正在做类似的事情,虽然还没有实现完整的解决方案。

此代码发生在我在演示者中处理的按钮的单击事件上。该模块在配置文件中定义。

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)
于 2009-06-17T14:29:17.700 回答