【问题标题】:PRISM RegionManager not adding regions of the ShellPRISM RegionManager 不添加 Shell 的区域
【发布时间】:2011-08-28 02:23:27
【问题描述】:

我有一个主 WPF 应用程序和其他模块,我正在使用 PRISM 来托管在我的 Shell 中定义的不同区域中的模块视图。这对我来说很好。 我现在需要将我的主应用程序设置为类库并从另一个窗口应用程序调用它。 这个新的 Window 应用程序有一个 Main 函数,代码如下。

[System.STAThreadAttribute()]
    public static void Main()
    {
        Application app = new Application();
        IStartupUI start = new StartupUI();
        start.StartUserInterface();                      
        app.Run();
    }

start.StartUserInterface 基本上是调用dll中的函数,代码如下

     ABCBootStrapper bootstrapper = new ABCBootStrapper ();
     bootstrapper.Run();

当 Dll 本身是主应用程序时,之前在 OnStartup 中调用了同一段代码。

现在有了这个更改,Shell 不会显示任何视图。在调试时,我发现 RegionManager 无法识别 Shell 中定义的任何区域。基本上注册到 RegionManager 的区域数量为 0。 在 shell 中定义的所有区域都是 ContentControl。

【问题讨论】:

    标签: wpf prism


    【解决方案1】:

    我的问题似乎已通过执行以下操作得到解决:

    我将包含 Main 函数的类派生自 System.Windows.Application 而不是直接创建 Application 的实例,而是创建了类的实例,并将用于启动用户界面的代码放入 OnStartup 事件处理程序中。

    class Test : System.Windows.Application
    {
        [System.STAThreadAttribute()]
        public static void Main()
        {
            Test app = new Test();
            app.Startup += new StartupEventHandler(app_Startup);
            app.Run();
        }
    
        static void app_Startup(object sender, StartupEventArgs e)
        {
    
            IStartupUI start = new StartupUI();
            start.StartUserInterface();
    
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多