3

我在 prism 库的上下文中从 xaml 文件加载模块时遇到问题。模块的 xaml 如下所示:

<Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:sys="clr-namespace:System;assembly=mscorlib" 
         xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">
<Modularity:ModuleInfoGroup InitializationMode="WhenAvailable">
    <Modularity:ModuleInfo Ref="file://HelloWorldModule.dll" ModuleName="HelloWorldModule" ModuleType="HelloWorldModule.Views.HelloWorldView, HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</Modularity:ModuleInfoGroup>

到目前为止,解析器找到了这个 xaml,但没有找到 HelloWorldModule.dll。我在文档中找不到任何有用的东西,因为这些都是针对 Silverlight 的,但我的项目是 WFP 应用程序。

shell.exe 的相对路径是:

\Projects\QFX_Shell\bin\Debug

HelloWorldModule.dll 的路径是:

\Projects\HelloWorldModule\bin\Debug

所以问题是“Ref”属性期望什么值?它是 HelloWorldModule.dll 的绝对路径吗?

第二个问题是 ModuleType 属性应该具有什么值:

namespace HelloWorldModule.Views
{
  /// <summary>
  /// Interaction logic for HelloWorldView.xaml
  /// </summary>
  public partial class HelloWorldView : UserControl
  {
    public HelloWorldView()
    {
        InitializeComponent();
    }
  }
}

类类型名称是否包含命名空间?

ModuleType="HelloWorldModule.Views.HelloWorldView, HelloWorldModule...

下一个问题是,HelloWorldModule.dll 是否与 Shell.exe 位于同一文件夹中?谢谢,于尔根

4

1 回答 1

1
  1. The ref attribute expects a path below the application path, if you use a relative path, or the absolute path, which usually doesnt work because you cannot know the installation folder during design time. To have the module catalog find your module you better copy the module to the application directory and use a relative path.
  2. The module type attribute has to be the type inside your module dll that implements the IModule interface.
  3. Yes, the namespace has to be included.
  4. See answer 1

For more advice about your questions, have a look at chapter 4, Modular Application Development of the Prism 4.0 - November 2010 manual.

于 2011-10-11T06:57:14.340 回答