首页 > 解决方案 > 如何在没有 Application 类或不覆盖它的项目中正确使用 WPF Prism?

问题描述

可以在不覆盖 Application 类的情况下使用 Prism 吗?例如,在为 Visual Studio 开发扩展时。我还没有找到如何做到这一点的例子。

标签: c#wpfprismvisual-studio-extensions

解决方案


答案就在这里。您可以使用相关代码,您仍然可以使用它们:

protected override Window CreateShell()
{
    return null;
}

protected override void OnInitialized()
{
    var shellWindow = Container.Resolve<ShellWindow>();
    shellWindow.Show();
    MainWindow = shellWindow.ParentOfType<Window>();

    // there lines was not executed because of null Shell - so must duplicate here. Originally called from PrismApplicationBase.Initialize
    RegionManager.SetRegionManager(MainWindow, Container.Resolve<IRegionManager>());
    RegionManager.UpdateRegions();
    InitializeModules();

    base.OnInitialized();
}

推荐阅读